pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: zengman <zengman@halodbtech.com>
To: Amit Langote <amitlangote09@gmail.com>
To: QQ Mail <781408517@qq.com>
Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #19625: SQL/JSON boolean DEFAULT expression silently replaced with 'false'
Date: Thu, 12 Nov 2026 22:50:10 +0800
Message-ID: <tencent_124CBD2106C4FF4726348D0F@qq.com> (raw)
In-Reply-To: <CA+HiwqGO9i5MUhOnnnXXrvKpou0A99wCfOuXrJcXRvTecmzTTg@mail.gmail.com>
References: <19625-683b498c92087bc8@postgresql.org>
	<tencent_0AAF798D129E099858B151E9@qq.com>
	<tencent_46CEA91A192F54AA1F1DC64B@qq.com>
	<tencent_3D4EE01AE90E43BA89A9B3AAB1B65C099B07@qq.com>
	<CA+HiwqGO9i5MUhOnnnXXrvKpou0A99wCfOuXrJcXRvTecmzTTg@mail.gmail.com>

> Thanks for the report and the patch.
> 
> Attached is v2, which I intend to commit and back-patch to v17. The
> main changes from the patch posted on Aug 24 are:
> 
> * I kept the existing jsonb Const for JSON_BEHAVIOR_TRUE and
> JSON_BEHAVIOR_FALSE, so only a boolean-valued DEFAULT expression gets
> wrapped in a to_jsonb() FuncExpr.  That way the node tree for TRUE /
> FALSE ON ERROR is unchanged in the back branches.
> 
> * More tests, including the cases asked for in the review posted on
> Oct 12 (NULL::boolean, JSON_QUERY with ON EMPTY, and a non-constant
> default).
> 
> * Added commit message noting that views and rules created before the
> fix still contain the wrong 'false'::jsonb
> 
> Bug #19822 reports the same problem and the cases shown there are
> fixed by this patch as well, so the commit message mentions that bug #
> too.

Hi Amit,

Thanks for reviewing my original patch and helping improve the fix. This looks much better than my previous version!
However, while testing it, I noticed a couple of issues in the following scenarios:

```sql
CREATE TABLE jidx(j jsonb);
CREATE INDEX ON jidx
  ((JSON_VALUE(j, '$.x' DEFAULT true ON EMPTY)));

CREATE TABLE jgen(
  j jsonb,
  x text GENERATED ALWAYS AS
    (JSON_VALUE(j, '$.x' DEFAULT true ON EMPTY)) STORED
);
```

```sql
postgres=# CREATE TABLE jidx(j jsonb);
CREATE TABLE
postgres=# CREATE INDEX ON jidx
  ((JSON_VALUE(j, '$.x' DEFAULT true ON EMPTY)));
2026-11-12 22:26:27.129 CST [2061352] ERROR:  functions in index expression must be marked IMMUTABLE at character 25
2026-11-12 22:26:27.129 CST [2061352] STATEMENT:  CREATE INDEX ON jidx
          ((JSON_VALUE(j, '$.x' DEFAULT true ON EMPTY)));
ERROR:  functions in index expression must be marked IMMUTABLE
LINE 2:   ((JSON_VALUE(j, '$.x' DEFAULT true ON EMPTY)));
           ^
postgres=# 
postgres=# 
postgres=# CREATE TABLE jgen(
  j jsonb,
  x text GENERATED ALWAYS AS
    (JSON_VALUE(j, '$.x' DEFAULT true ON EMPTY)) STORED
);
2026-11-12 22:26:33.169 CST [2061352] ERROR:  generation expression is not immutable
2026-11-12 22:26:33.169 CST [2061352] STATEMENT:  CREATE TABLE jgen(
          j jsonb,
          x text GENERATED ALWAYS AS
            (JSON_VALUE(j, '$.x' DEFAULT true ON EMPTY)) STORED
        );
ERROR:  generation expression is not immutable
```

I haven't come up with a good way to address these cases yet. Do you have any thoughts on this?
Thanks again!

--
Regards,
Man Zeng

view thread (7+ messages)  latest in thread

Message-ID: <tencent_124CBD2106C4FF4726348D0F@qq.com>
Permalink:  ../tencent_124CBD2106C4FF4726348D0F@qq.com/
Also on:    postgresql.org/message-id/tencent_124CBD2106C4FF4726348D0F@qq.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: zengman@halodbtech.com, amitlangote09@gmail.com, 781408517@qq.com
  Subject: Re: BUG #19625: SQL/JSON boolean DEFAULT expression silently replaced with 'false'
  In-Reply-To: <tencent_124CBD2106C4FF4726348D0F@qq.com>
  References: <19625-683b498c92087bc8@postgresql.org> <tencent_0AAF798D129E099858B151E9@qq.com> <tencent_46CEA91A192F54AA1F1DC64B@qq.com> <tencent_3D4EE01AE90E43BA89A9B3AAB1B65C099B07@qq.com> <CA+HiwqGO9i5MUhOnnnXXrvKpou0A99wCfOuXrJcXRvTecmzTTg@mail.gmail.com> <tencent_124CBD2106C4FF4726348D0F@qq.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