public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ayush Tiwari <[email protected]>
To: Richard Guo <[email protected]>
Cc: Melanie Plageman <[email protected]>
Cc: Nathan Bossart <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: Amit Langote <[email protected]>
Cc: Vik Fearing <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Álvaro Herrera <[email protected]>
Cc: Heikki Linnakangas <[email protected]>
Subject: Re: BUG #19418: SQL/JSON JSON_VALUE() does not conform to ISO/IEC 9075-2:2023(E) 6.34 <JSON value constructor>
Date: Thu, 7 May 2026 20:14:52 +0530
Message-ID: <CAJTYsWXPYqa58YXrU+SQMVonsAhjLS46HNUMU=wO5zm9MgY3_g@mail.gmail.com> (raw)
In-Reply-To: <CAMbWs4_TLsrWftz=TzpT9=fp=01LAZWRmdDLUMA9qTzMtXZwig@mail.gmail.com>
References: <[email protected]>
	<CAMbWs49P2z40f5yb_97ErwtC9ocdR5QQN0gWUZtjgot9+iGAcg@mail.gmail.com>
	<CAMbWs4-NuYP+0Zq9=Ufwy5GcM0XQnEqWjJFucaRGO4EQgiCcow@mail.gmail.com>
	<CAMbWs4-ra9mkBhUs2kmB5KxWuo80oAA33gZ=8JmRxmG3qGNxUg@mail.gmail.com>
	<CA+HiwqEtiTNV2v2P0HGa0B1TMNfmPweKXMZEOYPoQuFf3ZhsXQ@mail.gmail.com>
	<CAMbWs49tDE_niKLr4mzsa2BkX7fkWrorBzWheKTBziZ7z9-AuQ@mail.gmail.com>
	<CAMbWs48KEdgyJhxCOysaRdRJ5NzPObUET+5XbvyiqDfqyABEwg@mail.gmail.com>
	<[email protected]>
	<CAMbWs4_vqNEcHpvKFeFxfRoisrvw6yJ3styhS-arQDHZirw5cQ@mail.gmail.com>
	<CAMbWs49ps9eGWvkwc64ytUxdK0s-=xdFjtf64WyGp65EgTZ_LQ@mail.gmail.com>
	<aevLYeoSSgiwEiO-@nathan>
	<CAAKRu_YU542L_+_H1VFSTtLnj4Yo=GcXykyiw_6GZZiOEt5mVA@mail.gmail.com>
	<CAMbWs4_n8f2kPHkEw=ToZMh2FAzc6BDXq9uND-iY9-MB_fE_Vg@mail.gmail.com>
	<CAMbWs4_TLsrWftz=TzpT9=fp=01LAZWRmdDLUMA9qTzMtXZwig@mail.gmail.com>

Hi,


On Fri, 1 May 2026 at 06:53, Richard Guo <[email protected]> wrote:

> On Fri, May 1, 2026 at 9:26 AM Richard Guo <[email protected]> wrote:
> > Thank you, Nathan and Melanie.  I now have two of the three RMT
> > approvals, so I believe I'm good to go.  Will commit this shortly.
>
> Committed.
>

While looking at the JSON_ARRAY(query) empty-set fix, I noticed what
looks like a typmod issue in the new empty-array fallback.

I understand from this discussion that returning [] for an empty
JSON_ARRAY(query) input is intentional and required by SQL/JSON.  This
report is
about the RETURNING typmod not being enforced on that new [] fallback.

The non-empty query form enforces the RETURNING typmod:

  SELECT JSON_ARRAY(SELECT 1 RETURNING varchar(1));
  ERROR:  value too long for type character varying(1)

but the empty query form returns a value that does not fit the declared
type:

  SELECT JSON_ARRAY(SELECT 1 WHERE false RETURNING varchar(1));
   json_array
  ------------
   []
  (1 row)

The same inconsistency is visible through a view: the column is stored as
varchar(1), and pg_get_viewdef() shows RETURNING character varying(1), but
executing the view can still return the two-character value [].

The issue appears to be in transformJsonArrayQueryConstructor(): the
COALESCE
fallback builds the empty-array constant with typmod -1, and later
eval_const_expressions() replaces JSCTOR_JSON_ARRAY_QUERY with this
pre-built
func expression.  At that point the JsonConstructorExpr wrapper's RETURNING
typmod is no longer enough to enforce varchar(1).

I think the right fix is probably to make the executable expression stored
in
func carry the RETURNING typmod coercion.  This would also match the
direction
sketched earlier in the thread, where the fallback was described as
'[]'::[RETURNING_TYPE].  For example, coerceJsonFuncExpr() could notice
same-type/different-typmod cases, and transformJsonArrayQueryConstructor()
could
apply it to the COALESCE expression before storing that expression in the
JSCTOR_JSON_ARRAY_QUERY node.

Regards,
Ayush


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: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: BUG #19418: SQL/JSON JSON_VALUE() does not conform to ISO/IEC 9075-2:2023(E) 6.34 <JSON value constructor>
  In-Reply-To: <CAJTYsWXPYqa58YXrU+SQMVonsAhjLS46HNUMU=wO5zm9MgY3_g@mail.gmail.com>

* 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