| From: | shihao zhong <zhong950419(at)gmail(dot)com> |
|---|---|
| To: | Dirkjan Bussink <d(dot)bussink(at)gmail(dot)com> |
| Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: JSON_SERIALIZE for JSONB returns parts of the internal JSONB representation |
| Date: | 2026-09-19 03:19:51 |
| Message-ID: | CAGRkXqQXwh_gJmQE3PZj0v13omMPgFGBbb8TJoBFH8ECsAFCUg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Dirkjan,
Thanks for reporting this issue.
> select JSON_SERIALIZE('[1,2,4]'::jsonb);
> \x03
Reproduced on master. The docs allow any JSON type here, so it should
work. makeJsonConstructorExpr() builds the output coercion for a json
input, because it looks at the RETURNING format, which is always JSON.
The jsonb argument is passed through as is, so json_out() runs on it.
0001 fixes this issue.
0002 adds tests and is optional.
The fix is in the parser, so a view created before it stays wrong until
recreated.
Other options I looked at:
- convert in the executor. Covers old views, but adds a step there and
keeps the wrong coercion in the tree.
- cast jsonb to json in transformJsonSerializeExpr(). Works, converts
twice.
Thanks,
Shihao
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0002-Add-tests-for-JSON_SERIALIZE-with-a-jsonb-argumen.patch | application/octet-stream | 2.1 KB |
| v1-0001-Fix-JSON_SERIALIZE-with-a-jsonb-argument.patch | application/octet-stream | 1.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | shihao zhong | 2026-09-19 03:34:37 | Re: BUG #19693: JSON_VALUE/JSON_QUERY PASSING a toasted text value reads the toast pointer instead of the text |
| Previous Message | shihao zhong | 2026-09-19 03:05:45 | Re: bug: Gather rescan keeps the first scan's tuple bound in workers |