| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | e1638616(at)u(dot)nus(dot)edu |
| Subject: | BUG #19970: json #> finds a nested key under an earlier duplicate key |
| Date: | 2026-12-02 13:17:10 |
| Message-ID: | 19970-ce2ab938d31adac4@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19970
Logged by: Yibo Dong
Email address: e1638616(at)u(dot)nus(dot)edu
PostgreSQL version: 19.0
Operating system: macOS 15 arm64.
Description:
For json with duplicate keys, the last value is the operative one, and
-> 'a' returns {"c": 2}. #> '{a,b}' and json_extract_path(j, 'a', 'b')
(also #>> and json_extract_path_text) return 1 from the earlier "a",
while -> 'a' -> 'b' and the jsonb cast return NULL.
Steps to reproduce:
SELECT '{"a": {"b": 1}, "a": {"c": 2}}'::json -> 'a' AS a_value,
'{"a": {"b": 1}, "a": {"c": 2}}'::json -> 'a' -> 'b' AS chained,
'{"a": {"b": 1}, "a": {"c": 2}}'::json #> '{a,b}' AS path_op,
json_extract_path('{"a": {"b": 1}, "a": {"c": 2}}', 'a', 'b') AS
extract_path,
'{"a": {"b": 1}, "a": {"c": 2}}'::json::jsonb #> '{a,b}' AS
via_jsonb;
Actual result (psql -P null=NULL):
a_value | chained | path_op | extract_path | via_jsonb
----------+---------+---------+--------------+-----------
{"c": 2} | NULL | 1 | 1 | NULL
Expected result: path_op and extract_path are NULL, like chained and
via_jsonb.
PostgreSQL 19.0 (Homebrew), macOS 15 arm64.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | PG Bug reporting form | 2026-12-02 13:27:33 | BUG #19971: JSON_VALUE RETURNING json drops the quotes of a jsonb string DEFAULT |
| Previous Message | Amit Langote | 2026-12-02 12:54:51 | Re: BUG #19851: Adding a tautological CHECK(true) to a domain changes JSON_VALUE's result (silent NULL, value/type c |