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