pgsql: SQL/JSON: Fix casting for integer EXISTS columns in JSON_TABLE

From: Amit Langote <amitlan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: SQL/JSON: Fix casting for integer EXISTS columns in JSON_TABLE
Date: 2024-07-30 02:00:50
Message-ID: E1sYcAU-001pLt-6z@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)universality(at)gmail(dot)com>
Author: Jian He <jian(dot)universality(at)gmail(dot)com>
Author: Amit Langote <amitlangote09(at)gmail(dot)com>
Discussion: https://postgr.es/m/CACJufxEo4sUjKCYtda0_qt9tazqqKPmF1cqhW9KBOUeJFqQd2g@mail.gmail.com
Backpatch-through: 17

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7f56eaff2fb0f3541c5c6ef8c1099e7f0618b461

Modified Files
--------------
src/backend/executor/execExpr.c | 19 +++++++---
src/backend/executor/execExprInterp.c | 46 ++++++++++++++++++++-----
src/include/executor/execExpr.h | 6 +++-
src/test/regress/expected/sqljson_jsontable.out | 34 ++++++++++++++++--
src/test/regress/sql/sqljson_jsontable.sql | 13 ++++++-
5 files changed, 102 insertions(+), 16 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2024-07-30 06:14:01 pgsql: Add more debugging information when failing to read pgstats file
Previous Message Amit Langote 2024-07-30 02:00:36 pgsql: SQL/JSON: Fix casting for integer EXISTS columns in JSON_TABLE