Re: BUG #19418: SQL/JSON JSON_VALUE() does not conform to ISO/IEC 9075-2:2023(E) 6.34 - Mailing list pgsql-bugs

From Richard Guo
Subject Re: BUG #19418: SQL/JSON JSON_VALUE() does not conform to ISO/IEC 9075-2:2023(E) 6.34
Date
Msg-id CAMbWs4-yH6nsC4na99rWeXzA+sLXvJdtcevgkQDEU6RwJNbFKQ@mail.gmail.com
Whole thread
In response to Re: BUG #19418: SQL/JSON JSON_VALUE() does not conform to ISO/IEC 9075-2:2023(E) 6.34  (Ayush Tiwari <ayushtiwari.slg01@gmail.com>)
List pgsql-bugs
On Thu, May 7, 2026 at 11:45 PM Ayush Tiwari
<ayushtiwari.slg01@gmail.com> wrote:
> 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)

Nice catch.  The empty-array Const was built with typmod -1, and the
type input function was invoked with typmod -1, so any RETURNING
length restriction was silently bypassed.

I've pushed a fix that builds Const and calls the input function with
the typmod of the non-empty COALESCE argument.

- Richard



pgsql-bugs by date:

Previous
From: Michał Tęcza
Date:
Subject: pg_restore: error: could not execute query: ERROR: schema does not exist
Next
From: Fujii Masao
Date:
Subject: Re: pg_restore: error: could not execute query: ERROR: schema does not exist