BUG #19736: `JSON_OBJECT ... ABSENT ON NULL` accepts invalid keys when the value is NULL - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #19736: `JSON_OBJECT ... ABSENT ON NULL` accepts invalid keys when the value is NULL
Date
Msg-id 19736-3a44617ea5534c77@postgresql.org
Whole thread
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      19736
Logged by:          Shallow
Email address:      theshallow27@gmail.com
PostgreSQL version: 18.6
Operating system:   Linux
Description:

When `ABSENT ON NULL` removes a pair because its value is SQL NULL,
`JSON_OBJECT` also skips validation of that pair's key. The documented
restrictions say that a key cannot be NULL and must be a scalar expression
without a cast to JSON. Those restrictions should still apply when the value
pair will be omitted.

**Reproduction:**

```sql
SELECT JSON_OBJECT((NULL::text) VALUE NULL::text
                   ABSENT ON NULL RETURNING json);

SELECT JSON_OBJECT((ARRAY[1,2]) VALUE NULL::text
                   ABSENT ON NULL RETURNING json);
```

**Actual result:** Both statements return `{}`.

**Expected result:** Both statements should reject the invalid key, as the
key
restrictions apply regardless of whether the value is omitted.





pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #19735: `jsonb_object_agg_unique_strict` drops a JSONB `null` value as if it were SQL NULL
Next
From: PG Bug reporting form
Date:
Subject: BUG #19737: Empty `JSON_OBJECT` cannot use documented `ON NULL` or unique-key clauses