Re: BUG #19736: `JSON_OBJECT ... ABSENT ON NULL` accepts invalid keys when the value is NULL

From: QQ Mail <781408517(at)qq(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, theshallow27(at)gmail(dot)com
Subject: Re: BUG #19736: `JSON_OBJECT ... ABSENT ON NULL` accepts invalid keys when the value is NULL
Date: 2026-10-12 03:42:47
Message-ID: tencent_0BDC559B7560096958C395898FB3A3B1F507@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hi,

The attached patch addresses the SQL NULL-key part of this report. It was prepared with AI assistance, including the local build and test execution.

In json_build_object_worker(), the NULL-key check currently follows the ABSENT ON NULL skip. Moving that check before the skip makes JSON_OBJECT(NULL: NULL ABSENT ON NULL) reject the NULL key, as the RETURNING jsonb path already does. The existing error messages and SQLSTATEs are preserved.

The patch adds regression coverage for NULL keys with ABSENT ON NULL, for both json and jsonb output, with and without WITH UNIQUE KEYS. It does not address the separate array, composite, or JSON-key validation cases in this report.

The patch was built and tested against PostgreSQL master commit 9e7d152488f197e96f171f0714459c227c3f7693. With only the new regression tests applied, sqljson failed at the new NULL-key/ABSENT/json case. With the code change applied, sqljson and all nine JSON-family regression tests passed. Existing coverage for legitimate NULL-value omission and duplicate keys with omitted values continued to pass. git diff --check also passed.

Those are the results from the earlier local test run, not a new test run today. The environment was Linux x86_64, GCC 14.2.0, with --enable-cassert --without-readline --without-zlib --without-icu and CFLAGS='-O0 -g0'. This was focused regression testing, not the full PostgreSQL test suite or cross-platform validation.

Before sending, I rechecked that master still points to the same commit and verified that the attached patch passes git apply --check against freshly retrieved source files at that commit.

Comments on this narrowly scoped fix are welcome.

Attachment Content-Type Size
19736-null-key-validation.patch text/x-diff 2.7 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message QQ Mail 2026-10-12 06:35:25 Re: BUG #19736: `JSON_OBJECT ... ABSENT ON NULL` accepts invalid keys when the value is NULL
Previous Message QQ Mail 2026-10-12 03:33:59 Re: BUG #19625: SQL/JSON boolean DEFAULT expression silently replaced with 'false'

Browse pgsql-hackers by date

  From Date Subject
Next Message surya poondla 2026-10-12 04:11:24 Re: pg_walinspect: add functions to locate and list WAL by time and LSN
Previous Message jian he 2026-10-12 03:33:58 Re: [PG19] Three bugs with a CHECK constraint that only the child enforces