Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WzRPA-0005Wj-6n for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Jun 2014 14:09:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WzRP9-0006gS-N1 for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Jun 2014 14:08:59 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WzRP8-0006gH-HO; Tue, 24 Jun 2014 14:08:58 +0000 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1WzRP4-0003bU-Pf; Tue, 24 Jun 2014 14:08:56 +0000 Received: from mfilter21-d.gandi.net (mfilter21-d.gandi.net [217.70.178.149]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 86728A80B4; Tue, 24 Jun 2014 16:08:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter21-d.gandi.net Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by mfilter21-d.gandi.net (mfilter21-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id ZBhtiuWm6YIJ; Tue, 24 Jun 2014 16:08:18 +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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 8B001A80E5; Tue, 24 Jun 2014 16:08:17 +0200 (CEST) Message-ID: <53A9864F.4080305@dunslane.net> Date: Tue, 24 Jun 2014 10:08:15 -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: [HACKERS] BUG #10728: json_to_recordset with nested json objects NULLs columns References: <20140622153409.2618.90346@wrigleys.postgresql.org> <16858.1403538180@sss.pgh.pa.us> <53A8877F.7060208@dunslane.net> <17766.1403566448@sss.pgh.pa.us> <53A8C780.2070701@dunslane.net> <20561.1403574211@sss.pgh.pa.us> In-Reply-To: <20561.1403574211@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-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 06/23/2014 09:43 PM, Tom Lane wrote: > Andrew Dunstan writes: >> On 06/23/2014 07:34 PM, Tom Lane wrote: >>> I'm not following your comment about 9.3. The json[b]_to_record[set] >>> functions are new in 9.4, which is what makes me feel it's not too >>> late to redefine their behavior. But changing behavior of stuff that >>> was in 9.3 seems a lot more debatable. >> This problem is also manifest in json_populate_recordset, which also >> uses the function in question, and is in 9.3: > Ah, I see the problem. > > Here is a first cut suggestion: > > * Get rid of the use_json_as_text flag argument for the new functions. > In json_populate_record(set), ignore its value and deprecate using it. > (The fact that it already had a default makes that easier.) The > behavior should always be as below. > > * For nested json objects, we'll spit those out in json textual format, > which means they'll successfully convert to either text or json/jsonb. > Compared to the old behavior of json_populate_recordset, this just means > that we don't throw an error anymore regardless of the flag value, > which seems ok (though maybe not something to backpatch into 9.3). > > * Nested json arrays are a bit more problematic. What I'd ideally like > is to spit them out in a form that would be successfully parsable as a SQL > array of the appropriate element type. Unfortunately, I think that that > ship has sailed because json_populate_recordset failed to do that in 9.3. > What we should probably do is define this the same as the nested object > case, ie, we spit it out in *json* array format, meaning you can insert it > into a text or json/jsonb field of the result record. Maybe sometime in > the future we can add a json-array-to-SQL-array converter function, but > these functions won't do that. > > >From a user's standpoint this just boils down to (a) fix the bug with > mishandling of the hash tables, and (b) get rid of the gratuitous > error report. > > The big problem is that we have been ignoring the result type when constructing the hash, even though the info is available. There is some sense in this in that the field might not even be present in the result type. And it works except for structured types like records, arrays and json. Even if we don't have a nested value, the functions will do the wrong thing for a scalar string destined for a json field (it will be de-escaped, when it should not be). w.r.t. json arrays, I think you're chasing a chimera, since they are heterogenous, unlike SQL arrays. w.r.t. the use_json_as_text argument, yes, it has a default, but the default is false. Ignoring it seems to be more than just deprecating it. I agree it's a mess, though :-( 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