pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joao Rito <joaovictor.rito@gmail.com>
To: Yeongjae Min <dudwo990413@gmail.com>
Cc: Dmitry Dolgov <9erthalion6@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Cc: pgsql-bugs@lists.postgresql.org
Cc: theshallow27@gmail.com
Subject: Re: BUG #19736: `JSON_OBJECT ... ABSENT ON NULL` accepts invalid keys when the value is NULL
Date: Sun, 15 Nov 2026 05:46:50 -0300
Message-ID: <20261115084650.45010-1-joaovictor.rito@gmail.com> (raw)
In-Reply-To: <CAP=tSTAKkF6=NfGHRmPB7XyWescAxxqBAxa4YwFRk_tQg_0q3Q@mail.gmail.com>
References: <19736-3a44617ea5534c77@postgresql.org>
	<CAP=tSTAKkF6=NfGHRmPB7XyWescAxxqBAxa4YwFRk_tQg_0q3Q@mail.gmail.com>

Hi Yeongjae,

Thanks for the patch. I tested v3 on current master (81b2179b492, built
with cassert and tap tests) and it applies cleanly. On master, with a
NULL key and a NULL value, JSON_OBJECT ... ABSENT ON NULL RETURNING json
returns {} instead of an error. The same happens for an array key, a ROW
key, and json and jsonb keys, with RETURNING json and jsonb, and for a
domain over int[] with RETURNING json. A jsonb NULL key with a NULL
value already fails on master ("argument 1: key must not be null"), so
the NULL key problem is only in the json path. Two aggregate cases,
json_object_agg_strict(ARRAY[1], NULL::text) and
jsonb_object_agg_strict('{"a":1}'::jsonb, NULL::text), also returned an
empty object on master. Dmitry already raised the aggregate case. I only
confirm it on current master.

With the patch all of these raise an error: "null value not allowed for
object key" for the json path and "key value must be scalar, not array,
composite, or json" for non-scalar keys. A composite key with a cast to
json and a NULL value is now rejected, as it already was with a non-NULL
value. A valid key with a NULL value is still omitted (tested with text,
int, numeric, bool, timestamptz, name, bytea, int4range and enum keys).
A NULL key with a non-NULL value still fails as on master. With WITH
UNIQUE KEYS, duplicate keys with omitted values and a NULL key with a
NULL value (json) give the same result as master. json_build_object,
jsonb_build_object and json_object(text[]) also give the same output as
master. The regress suite passes (243 subtests) and the server log has
no TRAP or assertion lines.

What I did not test: check-world, the isolation and tap suites,
pgindent, the docs change and its build, the back branches, other
platforms (I ran one Linux build), planning or performance effects, and
a detailed read of the C code.

I found no problem with the patch from what I could test.

Regards,
Joao Rito






view thread (10+ messages)  latest in thread

Message-ID: <20261115084650.45010-1-joaovictor.rito@gmail.com>
Permalink:  ../20261115084650.45010-1-joaovictor.rito@gmail.com/
Also on:    postgresql.org/message-id/20261115084650.45010-1-joaovictor.rito@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: joaovictor.rito@gmail.com, dudwo990413@gmail.com, 9erthalion6@gmail.com, pgsql-hackers@lists.postgresql.org, theshallow27@gmail.com
  Subject: Re: BUG #19736: `JSON_OBJECT ... ABSENT ON NULL` accepts invalid keys when the value is NULL
  In-Reply-To: <20261115084650.45010-1-joaovictor.rito@gmail.com>
  References: <19736-3a44617ea5534c77@postgresql.org> <CAP=tSTAKkF6=NfGHRmPB7XyWescAxxqBAxa4YwFRk_tQg_0q3Q@mail.gmail.com> <20261115084650.45010-1-joaovictor.rito@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox