SQL/JSON: Fix casting for integer EXISTS columns in JSON_TABLE
authorAmit Langote <amitlan@postgresql.org>
Tue, 30 Jul 2024 01:12:23 +0000 (10:12 +0900)
committerAmit Langote <amitlan@postgresql.org>
Tue, 30 Jul 2024 01:34:17 +0000 (10:34 +0900)
commit7f56eaff2fb0f3541c5c6ef8c1099e7f0618b461
treed03b8c513567f5a085ec15395bb57fff9677b596
parent74c96699be3f53c058c8794c07952221b9625b4f
SQL/JSON: Fix casting for integer EXISTS columns in JSON_TABLE

The current method of coercing the boolean result value of
JsonPathExists() to the target type specified for an EXISTS column,
which is to call the type's input function via json_populate_type(),
leads to an error when the target type is integer, because the
integer input function doesn't recognize boolean literal values as
valid.

Instead use the boolean-to-integer cast function for coercion in that
case so that using integer or domains thereof as type for EXISTS
columns works. Note that coercion for ON ERROR values TRUE and FALSE
already works like that because the parser creates a cast expression
including the cast function, but the coercion of the actual result
value is not handled by the parser.

Tests by Jian He.

Reported-by: Jian He <jian.universality@gmail.com>
Author: Jian He <jian.universality@gmail.com>
Author: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/CACJufxEo4sUjKCYtda0_qt9tazqqKPmF1cqhW9KBOUeJFqQd2g@mail.gmail.com
Backpatch-through: 17
src/backend/executor/execExpr.c
src/backend/executor/execExprInterp.c
src/include/executor/execExpr.h
src/test/regress/expected/sqljson_jsontable.out
src/test/regress/sql/sqljson_jsontable.sql