Fix json_to_record() bug with nested objects.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 3 Mar 2016 04:31:39 +0000 (23:31 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 3 Mar 2016 04:31:39 +0000 (23:31 -0500)
commita9d199f6d3b998929cdb8e8aa61e5cd8db9b220f
tree9b82a1bccdedf2b6cd7ebcb64eed8c427ccc3a7f
parenteb43e851d6b3fa0c4516efcfdf29a183f7717a43
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.
src/backend/utils/adt/jsonfuncs.c
src/test/regress/expected/json.out
src/test/regress/expected/jsonb.out
src/test/regress/sql/json.sql
src/test/regress/sql/jsonb.sql