From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: venu2805k@gmail.com
Subject: BUG #19768: JSON_TABLE: row/text comparisons in context item or PASSING give wrong results or spurious collation
Date: Fri, 16 Oct 2026 22:51:01 +0000
Message-ID: <19768-3633daa830be95db@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 19768
Logged by: Venu Kummari
Email address: venu2805k@gmail.com
PostgreSQL version: 18.6
Operating system: Linux x86_64
Description:
PostgreSQL versions: 17.11, 18.6, master (26bd08f). Tested from source on
Linux x86_64.
The JSON_TABLE context-item expression fails to assign collations correctly,
causing incorrect results for row comparisons and collation errors for valid
text comparisons.
1. Incorrect result / assertion failure:
SELECT * FROM JSON_TABLE(
jsonb_build_object('k', ROW(1, 2) < ROW(3, 4)),
'$'
COLUMNS (a bool PATH '$.k')
);
Expected: t
Actual: f on PostgreSQL 17.11 and 18.6. On an assertion-enabled master
build, the backend fails with:
TRAP: failed Assert("list_length(rcexpr->inputcollids) == nopers"), File:
"execExpr.c", Line: 2078
2. Collation error in the context item:
SELECT * FROM JSON_TABLE(
jsonb_build_object('k', 'a' < 'b' COLLATE "C"),
'$'
COLUMNS (a bool PATH '$.k')
);
Expected: t
Actual: ERROR: could not determine which collation to use for string
comparison
3. Collation error in a PASSING argument:
SELECT * FROM JSON_TABLE(
jsonb '{}',
'$' PASSING 'a' < 'b' COLLATE "C" AS x
COLUMNS (a bool PATH '$x')
);
This also fails with "could not determine which collation to use for string
comparison", despite the explicit COLLATE clause.
The same expressions work outside JSON_TABLE.
Suspected cause: transformJsonTable() in
src/backend/parser/parse_jsontable.c does not call assign_expr_collations()
for the context-item expression and PASSING arguments. The corresponding
XMLTABLE transformation performs collation assignment, as do JSON_TABLE
column expressions.
Without the required collation information, a RowCompareExpr can have an
empty inputcollids list, causing the executor to compare zero columns and
return an incorrect result.
A proposed patch adds the missing collation assignment and regression tests.
The patch was tested on master, and the core regression suite passed
(239/239 tests). The source change applies to REL_17_STABLE and
REL_18_STABLE.
The bug was discovered through grammar-based fuzzing.
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-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, venu2805k@gmail.com
Subject: Re: BUG #19768: JSON_TABLE: row/text comparisons in context item or PASSING give wrong results or spurious collation
In-Reply-To: <19768-3633daa830be95db@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