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: JSON_TABLE: fix missing collation assignments
Date: Fri, 06 Nov 2026 08:31:57 +0000
Message-ID: <E1xPFMb-00000000RXu-1J91@gemulon.postgresql.org> (raw)

JSON_TABLE: fix missing collation assignments

transformJsonTable() transforms the context item and the PASSING
arguments into the JsonExpr stored in TableFunc.docexpr, and copies the
transformed PASSING arguments into TableFunc.passingvalexprs, but never
ran assign_expr_collations() over them.  That is needed here because
assign_query_collations() doesn't look into the range table, which is
why transformRangeTableFunc() does it for XMLTABLE, as does
transformJsonTableColumn() for JSON_TABLE's own column expressions.

As a result, expressions in there were left without collations.  A text
comparison failed with "could not determine which collation to use for
string comparison", even with an explicit COLLATE clause, and a row
comparison was left with an empty inputcollids list, which made the
executor compare zero columns and return the result for equal rows (so
ROW(1, 2) < ROW(3, 4) yielded false), or trip an assertion in
ExecInitExprRec() in assert-enabled builds.

Fix by calling assign_expr_collations() on the transformed JsonExpr,
before the PASSING arguments are copied out of it.

Oversight in commit de3600452b6, so back-patch to 17.

Bug: #19768
Reported-by: Venu Kummari <venu2805k@gmail.com>
Author: Venu Kummari <venu2805k@gmail.com>
Discussion: https://postgr.es/m/19768-3633daa830be95db@postgresql.org
Backpatch-through: 17

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3d72e63b825afa64848fd057ea937f89ec61d521

Modified Files
--------------
src/backend/parser/parse_jsontable.c            |  8 +++++++
src/test/regress/expected/sqljson_jsontable.out | 30 +++++++++++++++++++++++++
src/test/regress/sql/sqljson_jsontable.sql      | 11 +++++++++
3 files changed, 49 insertions(+)



view thread (4+ messages)  latest in thread

Message-ID: <E1xPFMb-00000000RXu-1J91@gemulon.postgresql.org>
Permalink:  ../E1xPFMb-00000000RXu-1J91@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xPFMb-00000000RXu-1J91@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: amitlan@postgresql.org
  Subject: Re: pgsql: JSON_TABLE: fix missing collation assignments
  In-Reply-To: <E1xPFMb-00000000RXu-1J91@gemulon.postgresql.org>
  References: <E1xPFMb-00000000RXu-1J91@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