From: Joao Rito <joaovictor.rito@gmail.com>
To: Amit Langote <amitlangote09@gmail.com>
Cc: Man Zeng <zengman@halodbtech.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19625: SQL/JSON boolean DEFAULT expression silently replaced with 'false'
Date: Sun, 15 Nov 2026 00:54:32 -0300
Message-ID: <20261115035432.23742-1-joaovictor.rito@gmail.com> (raw)
In-Reply-To: <tencent_124CBD2106C4FF4726348D0F@qq.com>
References: <tencent_124CBD2106C4FF4726348D0F@qq.com>
Hi Amit, Man,
I tested v2 on current master (81b2179b492, built with cassert and tap tests) and it applies cleanly. On master, a boolean DEFAULT ON ERROR or ON EMPTY returned 'false' in every case I ran where the result was not already boolean: DEFAULT true, NULL::bool (the result was not NULL), (1 = 1) and (random() < 2, ON ERROR only), in JSON_VALUE, JSON_QUERY and JSON_TABLE. I used RETURNING text, char(5), varchar(10), json and jsonb. RETURNING bool was already correct on master. With v2 all of them return the expected value, and a view shows DEFAULT to_jsonb(true) and gives the same result. DEFAULT 'abc', 42, a numeric, a date and a jsonb object, and JSON_EXISTS with TRUE/FALSE/UNKNOWN ON ERROR, give the same results as on master. The new test in sqljson_queryfuncs fails on master without the C change (it shows false | false | f where true | false | t is expected), and the regress suite passes with the patch (243 tests).
I could also reproduce what Man reported after v2. On master, CREATE INDEX on JSON_VALUE(j, '$.x' DEFAULT true ON EMPTY) and a STORED generated column with the same expression both work. With v2 they fail with "functions in index expression must be marked IMMUTABLE" and "generation expression is not immutable", because to_jsonb(anyelement) is STABLE. With a non-boolean DEFAULT, the index (text, and RETURNING int) and the generated column (text) still work with v2.
What I did not test: the isolation and tap suites, pgindent, the docs, the back branches (v17 onward), other platforms (I ran one Linux build), and a fix for the immutability issue.
Small suggestion: since the index and generated column cases work today, maybe the fix could avoid a STABLE function for a constant boolean DEFAULT (for example by building the jsonb Const at parse time, as the TRUE and FALSE behaviors do), and the test could cover an index or generated column. I do not have a tested patch for that. I have no objection to the rest of the approach.
Regards,
Joao Rito
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, amitlangote09@gmail.com, zengman@halodbtech.com
Subject: Re: BUG #19625: SQL/JSON boolean DEFAULT expression silently replaced with 'false'
In-Reply-To: <20261115035432.23742-1-joaovictor.rito@gmail.com>
References: <tencent_124CBD2106C4FF4726348D0F@qq.com> <20261115035432.23742-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