Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1abJVx-0001uC-Lz for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Mar 2016 03:01:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1abJVw-0007Ys-WD for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Mar 2016 03:01:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1abJVJ-0006T5-LS for pgsql-bugs@postgresql.org; Thu, 03 Mar 2016 03:00:41 +0000 Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1abJVG-00081m-W5 for pgsql-bugs@postgresql.org; Thu, 03 Mar 2016 03:00:40 +0000 Received: from mfilter21-d.gandi.net (mfilter21-d.gandi.net [217.70.178.149]) by relay6-d.mail.gandi.net (Postfix) with ESMTP id 761AEFB89F; Thu, 3 Mar 2016 04:00:36 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter21-d.gandi.net Received: from relay6-d.mail.gandi.net ([IPv6:::ffff:217.70.183.198]) by mfilter21-d.gandi.net (mfilter21-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id FfGXFyORjU-q; Thu, 3 Mar 2016 04:00:34 +0100 (CET) X-Originating-IP: 98.122.164.227 Received: from [192.168.10.146] (unknown [98.122.164.227]) (Authenticated sender: adsend@dunslane.net) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id CB447FB886; Thu, 3 Mar 2016 04:00:33 +0100 (CET) Subject: Re: BUG #13996: json_to_record() returns non-NULL, malformed value for omitted key under some circumstances To: Tom Lane , johann@visagie.za.net References: <20160302080310.2629.98690@wrigleys.postgresql.org> <26373.1456967099@sss.pgh.pa.us> Cc: pgsql-bugs@postgresql.org From: Andrew Dunstan Message-ID: <56D7A8CC.2050206@dunslane.net> Date: Wed, 2 Mar 2016 22:00:28 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <26373.1456967099@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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