agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Make JSON_TABLE generated path names avoid collisions
Date: Tue, 14 Jul 2026 22:31:12 +0000
Message-ID: <E1wjlei-000CeZ-0D@gemulon.postgresql.org> (raw)

Make JSON_TABLE generated path names avoid collisions

generateJsonTablePathName() produced names of the form
"json_table_path_N" in the same namespace as user-supplied path and
column names, without checking whether the name was already in use.
When an unnamed NESTED path's generated name happened to match a
user-supplied path name that a PLAN clause referenced, two sibling paths
matched the same plan entry and one of them, together with its columns,
was silently dropped from the output.

Bump the counter until the generated name is unused, so a generated name
can no longer coincide with a user-supplied one.  The still-uncovered
path is then correctly reported as not found in the plan.

The row pattern (root) path is named before the user-supplied column and
path names are collected, so when it is left unnamed its generated name
could not avoid them either, and a user column or path named like a
generated name, e.g.

    SELECT * FROM JSON_TABLE(jsonb '1', '$'
                             COLUMNS (json_table_path_0 int PATH '$')) jt;

was rejected with a bogus "duplicate JSON_TABLE column or path name"
error.  Collect the user-supplied names first and generate the row
pattern path's name afterwards, so that it avoids all of them.  An
explicit root path name is still seeded into the namespace, so a column
duplicating it is still correctly rejected.

Reported-by: Thom Brown <thom@linux.com>
Discussion: https://postgr.es/m/CAA-aLv7aZGSExnbjJRw8eKkoXbu34TdoKLLA2gPye3aHjO5OSA@mail.gmail.com
Discussion: https://postgr.es/m/CAA-aLv5U94KD4C%2BLhAPYcCeGvs1xBMngcS5oEkZHN9YWwXUHsA%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cd5fd08be7ec1cef1a4c34791ce743954c2b2293

Modified Files
--------------
src/backend/parser/parse_jsontable.c            | 33 +++++++++++++++++++------
src/test/regress/expected/sqljson_jsontable.out | 25 +++++++++++++++++++
src/test/regress/sql/sqljson_jsontable.sql      | 18 ++++++++++++++
3 files changed, 68 insertions(+), 8 deletions(-)



Message-ID: <E1wjlei-000CeZ-0D@gemulon.postgresql.org>
Permalink:  ../E1wjlei-000CeZ-0D@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wjlei-000CeZ-0D@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Make JSON_TABLE generated path names avoid collisions
  In-Reply-To: <E1wjlei-000CeZ-0D@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox