mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Fix json_to_record() bug with nested objects.
A thinko concerning nesting depth caused json_to_record() to produce bogus output if a field of its input object contained a sub-object with a field name matching one of the requested output column names. Per bug #13996 from Johann Visagie. I added a regression test case based on his example, plus parallel tests for json_to_recordset, jsonb_to_record, jsonb_to_recordset. The latter three do not exhibit the same bug (which suggests that we may be missing some opportunities to share code...) but testing seems like a good idea in any case. Back-patch to 9.4 where these functions were introduced.
This commit is contained in:
@ -519,6 +519,13 @@ select * from json_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","
|
||||
select * from json_to_recordset('[{"a":1,"b":{"d":"foo"},"c":true},{"a":2,"c":false,"b":{"d":"bar"}}]')
|
||||
as x(a int, b json, c boolean);
|
||||
|
||||
select *, c is null as c_is_null
|
||||
from json_to_record('{"a":1, "b":{"c":16, "d":2}, "x":8}'::json)
|
||||
as t(a int, b json, c text, x int);
|
||||
|
||||
select *, c is null as c_is_null
|
||||
from json_to_recordset('[{"a":1, "b":{"c":16, "d":2}, "x":8}]'::json)
|
||||
as t(a int, b json, c text, x int);
|
||||
|
||||
-- json_strip_nulls
|
||||
|
||||
|
Reference in New Issue
Block a user