Re: BUG #19825: JSON_VALUE(... RETURNING <domain over json/jsonb>) loses the re-quoting of scalar strings and silent

From: Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com>
To: 303677365(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19825: JSON_VALUE(... RETURNING <domain over json/jsonb>) loses the re-quoting of scalar strings and silent
Date: 2026-11-28 15:27:19
Message-ID: CA+Y2Bmcrp+aKua4nxip-nY17t4nhwHQxEr9Js_pvRnckBgH+YA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Chunling,

Thanks for the report and for tracking down the cause. I can reproduce
it on master, 17, 18 and 19.

The attached patch does what you suggested. ExecInitJsonExpr() now
looks at the RETURNING type's base type, so a domain over json or jsonb
gets the quoted string, same as the base type. For a domain with a
CHECK, json_populate_type() is no longer told to strip the quotes.

The same flag also breaks a jsonb DEFAULT, even with no domain:

SELECT JSON_VALUE(jsonb '{}', '$.a' RETURNING json
DEFAULT jsonb '"123"' ON EMPTY);

gives the number 123 instead of the string "123", and DEFAULT jsonb
'"y"' fails to coerce. The patch fixes that too.

Since the check happens at executor startup, existing views pick up the
fix as well. I checked that on master with a view created by the
unpatched server.

The new tests in sqljson_queryfuncs fail without the fix. make check
passes on master, 17, 18 and 19, and the patch applies to all of them
as is.

Regards,
Ishjaap Singh

Attachment Content-Type Size
v1-0001-SQL-JSON-Fix-JSON_VALUE-RETURNING-a-domain-over-j.patch application/octet-stream 10.7 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Nitin Motiani 2026-11-28 15:54:37 Re: BUG #19951: levenshtein_less_equal returns 0 when exact distance is 1 with a negative cost
Previous Message Pierre Forstmann 2026-11-28 15:20:27 Re: BUG #19891: pg_restore ignores an explicitly empty -F argument