[PATCH] Reject duplicate SQL/JSON PASSING argument names

From: "Dewei Dai" <daidewei1970(at)163(dot)com>
To: "Pgsql Hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: [PATCH] Reject duplicate SQL/JSON PASSING argument names
Date: 2026-11-18 02:55:55
Message-ID: 202611181055551263943@163.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

The attached patch makes SQL/JSON PASSING clauses reject duplicate
variable names instead of silently using the first matching value.

For example, this previously returned only "comedy":

SELECT jt.kind
FROM JSON_TABLE(
'{ "favorites":[{ "kind" : "comedy" },{ "kind" : "drama" }] }',
'$.favorites[*]?(@.kind == $k1)'
PASSING 'comedy' AS k1, 'drama' AS k1
COLUMNS (kind text PATH '$.kind')
) AS jt;

With the patch it raises:

ERROR: PASSING argument name "k1" is not unique

The same check applies to JSON_EXISTS, JSON_QUERY, JSON_VALUE, and
JSON_TABLE because they all use transformJsonPassingArgs(). The patch
also adds regression tests for JSON_QUERY and JSON_TABLE.

The patch was tested with the full regression suite on current master.

Thanks,
DeWei Dai
HighGo Software Co., Ltd.
https://www.highgo.com/

daidewei1970(at)163(dot)com

Attachment Content-Type Size
0001-Reject-duplicate-PASSING-argument-names.patch application/octet-stream 5.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-11-18 03:16:31 Re: pg_walinspect: add functions to locate and list WAL by time and LSN
Previous Message David Rowley 2026-11-18 02:37:51 Re: Incremental Sort crash on a rescan that becomes bounded