pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Dunstan <andrew@dunslane.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: johann@visagie.za.net
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13996: json_to_record() returns non-NULL, malformed value for omitted key under some circumstances
Date: Wed, 2 Mar 2016 22:00:28 -0500
Message-ID: <56D7A8CC.2050206@dunslane.net> (raw)
In-Reply-To: <26373.1456967099@sss.pgh.pa.us>
References: <20160302080310.2629.98690@wrigleys.postgresql.org>
	<26373.1456967099@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>



On 03/02/2016 08:04 PM, Tom Lane wrote:
> johann@visagie.za.net writes:
>> SELECT t.*
>> FROM json_to_record('{"a":1, "b":{"c":16, "d":2}, "x":8}'::json)
>> AS t(a int, b json, c text, x int);
>> However, if (as in this example) another key in the JSON object - `b` in
>> this case - refers to a nested JSON object which *does* contain a key `c`,
>> the function returns a malformed JSON string as (text)  value for column
>> `c`:
>>   a |       b        |    c    | x
>> ---+----------------+---------+---
>>   1 | {"c":16,"d":2} | {"c":16 | 8
>> (1 row)
>
> AFAICT this is a simple thinko in the hash_object_field_end() callback,
> as per attached patch that fixes this and doesn't break any existing
> regression test cases.  Andrew, do you concur that this is correct,
> or is there something I'm missing about the tracking of lex_level?
>
> 			


Looks like you're right. lex_level is incremented at object/array start 
and decremented at object/array end. So keys of the outermost object 
will be at lex_level 1, and we shouldn't be using anything at a higher 
level. I guess we should add something like this as an extra regression 
test.

cheers

andrew


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (4+ messages)  latest in thread

Message-ID: <56D7A8CC.2050206@dunslane.net>
Permalink:  ../56D7A8CC.2050206@dunslane.net/
Also on:    postgresql.org/message-id/56D7A8CC.2050206@dunslane.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@dunslane.net, tgl@sss.pgh.pa.us, johann@visagie.za.net
  Subject: Re: BUG #13996: json_to_record() returns non-NULL, malformed value for omitted key under some circumstances
  In-Reply-To: <56D7A8CC.2050206@dunslane.net>
  References: <20160302080310.2629.98690@wrigleys.postgresql.org> <26373.1456967099@sss.pgh.pa.us> <56D7A8CC.2050206@dunslane.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox