From 429d6846572fe43dc11496adfeaecadf23925e3f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 2 Mar 2016 23:31:39 -0500 Subject: 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/backend/utils/adt/jsonfuncs.c') diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 80018de6f0e..a4842cbcd83 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -2438,7 +2438,7 @@ hash_object_field_end(void *state, char *fname, bool isnull) /* * Ignore nested fields. */ - if (_state->lex->lex_level > 2) + if (_state->lex->lex_level > 1) return; /* -- cgit v1.2.3