| From: | zengman <zengman(at)halodbtech(dot)com> |
|---|---|
| To: | Amit Langote <amitlangote09(at)gmail(dot)com>, QQ Mail <781408517(at)qq(dot)com> |
| Cc: | pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: BUG #19625: SQL/JSON boolean DEFAULT expression silently replaced with 'false' |
| Date: | 2026-11-12 14:50:10 |
| Message-ID: | tencent_124CBD2106C4FF4726348D0F@qq.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
> 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-11-12 15:22:41 | Re: BUG #19834: eager aggregation still evaluates volatile join clauses when the volatile function is inside a SubPl |
| Previous Message | Kacper Kuras | 2026-11-12 12:55:06 | Re: BUG #18754: Logical replication cannot restart if client sent a copyDone |