| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | shihao zhong <zhong950419(at)gmail(dot)com> |
| Cc: | 303677365(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19872: JSON_TABLE: an UNUSED PASSING argument's COLLATE leaks into the output columns (wrong results, persi |
| Date: | 2026-11-30 13:36:21 |
| Message-ID: | CACJufxGmFHmHXPA=ojNYPR7UK6zMOuyptT2xyLQd1C7n3_BJiA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On Mon, Nov 30, 2026 at 12:58 PM shihao zhong <zhong950419(at)gmail(dot)com> wrote:
>
> Hi,
>
> 0002 fixes the leak, which JSON_VALUE() and JSON_QUERY() have too. I
> would keep it in master only, because after pg_upgrade some indexes
> need a REINDEX and some partitioned tables silently miss rows.
>
Per doc:
"""
Each of these functions apply a path_expression (an SQL/JSON path
query) to a context_item (the document). See Section 9.17.2 for more
details on what the path_expression can contain. The path_expression
can also reference variables, whose values are specified with their
respective names in the PASSING clause that is supported by each
function.
"""
path_expression will coerce to jsonpath data type, PASSING clause is
just portion/part of path_expression.
The jsonpath type does not support collation.
So in parse_collate.c, we can just handle T_JsonExpr like childless
expression nodes.
But it seems your v2 is better than my attached version.
+ case T_JsonExpr:
+ {
+ /*
+ * The PASSING arguments only supply values for
+ * JSON path variables. They are independent of
+ * each other and don't contribute to the node's
+ * collation.
+ */
+ JsonExpr *expr = (JsonExpr *) node;
+
+ assign_list_collations(context->pstate,
+ expr->passing_values);
+ (void) assign_collations_walker(expr->formatted_expr,
+ &loccontext);
+ (void) assign_collations_walker(expr->path_spec,
+ &loccontext);
+ (void) assign_collations_walker((Node *) expr->on_empty,
+ &loccontext);
+ (void) assign_collations_walker((Node *) expr->on_error,
+ &loccontext);
The comments below are what I came up with
+ /*
+ * A JsonExpr's collation is determined solely
by its RETURNING
+ * clause, and was already set during parse analysis, so
+ * exprCollation() gives the right answer.
Its subexpressions
+ * don't contribute to it;
transformJsonFuncExpr() has already
+ * assigned their collations.
+ */
| Attachment | Content-Type | Size |
|---|---|---|
| fix_jsonexpr_collation.diff | text/x-patch | 2.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Kirill Reshke | 2026-11-30 13:17:05 | Re: BUG #19871: JSON_TABLE evaluates each PASSING argument once per column - a named variable $v gets different valu |