Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WzAQb-0003jv-7p for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Jun 2014 20:01:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WzAQa-0001FQ-L1 for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Jun 2014 20:01:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WzAQZ-0001D5-0Q; Mon, 23 Jun 2014 20:01:19 +0000 Received: from relay6-d.mail.gandi.net ([2001:4b98:c:538::198]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1WzAQV-00031Q-Rz; Mon, 23 Jun 2014 20:01:17 +0000 Received: from mfilter25-d.gandi.net (mfilter25-d.gandi.net [217.70.178.153]) by relay6-d.mail.gandi.net (Postfix) with ESMTP id E1C99FB8AC; Mon, 23 Jun 2014 22:01:12 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter25-d.gandi.net Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by mfilter25-d.gandi.net (mfilter25-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id oObXLEHPYKDv; Mon, 23 Jun 2014 22:01:11 +0200 (CEST) X-Originating-IP: 98.27.58.255 Received: from [192.168.10.146] (cpe-098-027-058-255.nc.res.rr.com [98.27.58.255]) (Authenticated sender: adsend@dunslane.net) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 94F01FB8A0; Mon, 23 Jun 2014 22:01:05 +0200 (CEST) Message-ID: <53A8877F.7060208@dunslane.net> Date: Mon, 23 Jun 2014 16:01:03 -0400 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Tom Lane CC: Michael Paquier , matti.hameister@technologygroup.de, pgsql-bugs@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: [BUGS] BUG #10728: json_to_recordset with nested json objects NULLs columns References: <20140622153409.2618.90346@wrigleys.postgresql.org> <16858.1403538180@sss.pgh.pa.us> In-Reply-To: <16858.1403538180@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 06/23/2014 11:43 AM, Tom Lane wrote: > Michael Paquier writes: >> Digging more into that, I have found the issue and a fix for it. It happens >> that populate_recordset_object_start, which is used to initialize the >> process for the population of the record, is taken *each* time a json >> object is found, re-creating every time the hash table for the parsing >> process, hence removing from PopulateRecordsetState all the entries already >> parsed and creating the problem reported by Matti. The fix I am proposing >> to fix this issue is rather simple: simply bypass the creation of the hash >> table if lex_level > 1 as we are in presence of a nested object and rely on >> the existing hash table. > Yes, this code is clearly not handling the nested-objects case correctly. > I had written a fix more or less equivalent to yours last night. > > However, it seems to me that these functions (json[b]_to_record[set]) are > handling the nested-json-objects case in a fairly brain-dead fashion to > start with. I would like to propose that we should think about getting > rid of the use_json_as_text flag arguments altogether. What purpose do > they serve? If we're going to the trouble of parsing the nested JSON > objects anyway, why don't we just reconstruct from that data? > > (IOW, we probably actually should have nested hash tables in this case. > I suspect that the current bug arose from incompletely-written logic > to do it like that.) > > Since we've already decided to force an initdb for 9.4beta2, it's not > quite too late to revisit this API, and I think it needs revisiting. > > Looks like we have some problems in this whole area, not just the new function, so we need to fix 9.3 also :-( IIRC, originally, the intention was to disallow nested json objects, but the use_json_as_text was put in as a possibly less drastic possibility. If we get rid of it our only recourse is to error out if we encounter nested json. I was probably remiss in not considering the likelihood of a json target field. I currently don't have lots of time to devote to this, sadly, but Michael's patch looks like a good minimal fix. cheers andrew -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers