Re: BUG #19737: Empty `JSON_OBJECT` cannot use documented `ON NULL` or unique-key clauses - Mailing list pgsql-bugs

From jian he
Subject Re: BUG #19737: Empty `JSON_OBJECT` cannot use documented `ON NULL` or unique-key clauses
Date
Msg-id CACJufxERBd7_cN9-3FSAg4+GEdvXcaNQBoOBr1ZQ7Kgcwx7WOQ@mail.gmail.com
Whole thread
In response to BUG #19737: Empty `JSON_OBJECT` cannot use documented `ON NULL` or unique-key clauses  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
On Sun, Oct 4, 2026 at 5:16 AM PG Bug reporting form <noreply@postgresql.org> wrote:

> The documented syntax makes the key/value pair list optional and says that
> an
> empty pair list constructs an empty object. However, adding any of the
> optional
> clauses without a pair causes a syntax error.
>
> **Reproduction:**
>
> ```sql
> SELECT JSON_OBJECT();                 -- returns {}
> SELECT JSON_OBJECT(NULL ON NULL);     -- syntax error, SQLSTATE 42601

JSON_ARRAY seems have the same situation.
The attached doc patch can this JSON_OBJECT doc issue.
the idea is to make json_object have 2 entries:

json_object ( { key_expression { VALUE | ':' } value_expression [ FORMAT JSON [ ENCODING UTF8 ] ] }[, ...] [ { NULL | ABSENT } ON NULL ] [ { WITH | WITHOUT } UNIQUE [ KEYS ] ] [ RETURNING data_type [ FORMAT JSON [ ENCODING UTF8 ] ] ])
json_object ( [ RETURNING data_type [ FORMAT JSON [ ENCODING UTF8 ] ] ])

It feels ugly with too much text crammed together; perhaps we need another way to solve this problem.



--
jian
https://www.enterprisedb.com/
Attachment

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #19738: `uuidv7(interval)` rejects sub-millisecond timestamps within the final 48-bit millisecond
Next
From: Tom Lane
Date:
Subject: Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"