pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: SQL/JSON: Fix casting for integer EXISTS columns in JSON_TABLE
Date: Tue, 30 Jul 2024 02:00:50 +0000
Message-ID: <E1sYcAU-001pLt-6z@gemulon.postgresql.org> (raw)

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

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(-)



view thread (2+ messages)

Message-ID: <E1sYcAU-001pLt-6z@gemulon.postgresql.org>
Permalink:  ../E1sYcAU-001pLt-6z@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1sYcAU-001pLt-6z@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: amitlan@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: SQL/JSON: Fix casting for integer EXISTS columns in JSON_TABLE
  In-Reply-To: <E1sYcAU-001pLt-6z@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox