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 <[email protected]> Author: Venu Kummari <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 17 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/e405a46c45bae070364ed143fb9d5a631422e5e4 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(+)
