Re: pg_stat_statements replaces SQL/JSON ON EMPTY / ON ERROR keywords with parameters

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Staroverov Ilja <i(dot)staroverov(at)ftdata(dot)ru>
Cc: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_stat_statements replaces SQL/JSON ON EMPTY / ON ERROR keywords with parameters
Date: 2026-10-22 08:28:23
Message-ID: atnJJiWcHyhd8_NI@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Oct 21, 2026 at 09:04:09AM +0000, Staroverov Ilja wrote:
> Agreed for 0003. 0002 changes neither: it only leaves the location of
> the behavior Consts unset, and locations are recorded, not hashed, so
> the query IDs stay the same. But it's your call whether that's worth
> back-patching.

v1 offers a nice coverage. I have noticed a couple of holes here and
there, but globally that was fine.

+ 2 | SELECT JSON_VALUE(js, $1 $2 ON EMPTY ERROR ON ERROR) FROM pgss_sqljson_tab

Urg, yeah. In this one $2 is a DEFAULT keyword. That's confusing..
Sami has mentioned that on another thread. It does not prevent doing
something with the tests first; query jumbing can sometimes feel
tricky to feel (not be!) right.

+ 2 | SELECT JSON_VALUE(js, $1 DEFAULT $2 ON EMPTY) FROM pgss_sqljson_tab
+ 1 | SELECT JSON_VALUE(js, $1 DEFAULT $2 ON ERROR) FROM pgss_sqljson_tab

These ones are separated due to the different last keywords, and
perhaps more arguable, but it's confusing to replace the
NULL/DEFAULT/EMPTY by dollar parameters. And we have quite a few more
of these incorrect patterns.

These SQL/JSON patterns are so various that adding a mention of the
defaults is a good idea. I've expanded that a bit more.

The ON ERROR and ON EMPTY patterns can also be combined together in a
single query. I've added more of them.

under NESTED, PATH is optional. Having patterns where it's gone seems
necessary to me. Similarly, no NESTED in a PLAN is the same a no
PLAN.

There were a few more patterns that were not treated in plans with
combinations of UNION, INNER, CROSS.. Things like UNION/UNION and
CROSS/CROSS included.

And a few more notes for things missing:
* WITHOUT UNIQUE
* JSON_ARRAYAGG(ORDER BY [DESC])
* JSON_TABLE(UNKNOWN ON ERROR)
* JSON_SERIALIZE(FORMAT)
* PASSING in JSON_QUERY

No backpatch can happen on that, I am afraid. The query ID stability
matters on stable branches, even if some if the keywords are currently
eaten due to the locations.
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Fujii Masao 2026-10-22 08:37:50 Re: START_REPLICATION silently truncates an overlong LSN component
Previous Message Takeshi Ideriha 2026-10-22 07:46:44 Re: BUG #19760: CLUSTER loses a row the transaction inserted and then updated in a rolled-back subtransaction