Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y9cZa-00033Q-67 for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Jan 2015 16:38:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y9cZZ-0006En-Md for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Jan 2015 16:38:05 +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 1Y9cZY-0006Eg-Pc for pgsql-hackers@postgresql.org; Fri, 09 Jan 2015 16:38:04 +0000 Received: from relay5-d.mail.gandi.net ([2001:4b98:c:538::197]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Y9cZR-0003jk-D1 for pgsql-hackers@postgresql.org; Fri, 09 Jan 2015 16:38:03 +0000 Received: from mfilter25-d.gandi.net (mfilter25-d.gandi.net [217.70.178.153]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 01B4A41C07A; Fri, 9 Jan 2015 17:37:53 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter25-d.gandi.net Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by mfilter25-d.gandi.net (mfilter25-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id hr2Md30D9KyJ; Fri, 9 Jan 2015 17:37:21 +0100 (CET) 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 relay5-d.mail.gandi.net (Postfix) with ESMTPSA id B472941C04E; Fri, 9 Jan 2015 17:37:20 +0100 (CET) Message-ID: <54B003BF.3090306@dunslane.net> Date: Fri, 09 Jan 2015 11:37:19 -0500 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Aaron Botsis CC: pgsql-hackers@postgresql.org, Francisco Olarte Subject: Re: Patch: [BUGS] BUG #12320: json parsing with embedded double quotes References: <87B56448-146A-4ECD-96D3-8B09B89D4EEA@bt-r.com> <54AD8CEF.3080904@dunslane.net> <54AEEC3C.10907@dunslane.net> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable 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 01/08/2015 08:42 PM, Aaron Botsis wrote: > >> On Jan 8, 2015, at 3:44 PM, Andrew Dunstan wrote: >> >> >> On 01/08/2015 03:05 PM, Aaron Botsis wrote: >>> >>>> It's also unnecessary. CSV format, while not designed for this, is nev= ertheless sufficiently flexible to allow successful import of json data mee= ting certain criteria (essentially no newlines), like this: >>>> >>>> copy the_table(jsonfield) >>>> from '/path/to/jsondata' >>>> csv quote e'\x01' delimiter e'\x02=92; >>> While perhaps unnecessary, given the size and simplicity of the patch, = IMO it=92s a no brainer to merge (it actually makes the code smaller by 3 l= ines). It also enables non-json use cases anytime one might want to preserv= e embedded escapes, or use different ones entirely. Do you see other reason= s not to commit it? >> >> Well, for one thing it's seriously incomplete. You need to be able to ch= ange the delimiter as well. Otherwise, any embedded tab in the json will ca= use you major grief. >> >> Currently the delimiter and the escape MUST be a single byte non-nul cha= racter, and there is a check for this in csv mode. Your patch would allow a= ny arbitrary string (including one of zero length) for the escape in text m= ode, and would then silently ignore all but the first byte. That's not the = way we like to do things. >> >> And, frankly, I would need to spend quite a lot more time thinking about= other implications than I have given it so far. This is an area where I te= nd to be VERY cautious about making changes. This is a fairly fragile ecosy= stem. > Good point. > > This version: > > * doesn't allow ENCODING in BINARY mode (existing bug) > * doesn=92t allow ESCAPE in BINARY mode > * makes COPY TO work with escape > * ensures escape char length is < 2 for text mode, 1 for CSV > > Couple more things to realize: setting both the escape and delimiter char= acters to null won=92t be any different than how you fiddled with them in C= SV mode. The code paths will be the same because we should never encounter = a null in the middle of the string. And even if we did (and the encoding di= dn=92t catch it), we=92d treat it just like any other field delimiter or es= cape character. > > So I=92m going to do a bit more testing with another patch tomorrow with = delimiters removed. If you can think of any specific cases you think will b= reak it let me know and I=92ll make sure to add regression tests for them a= s well. > > Well, I still need convincing that this is the best solution to the=20 problem. As I said, I need to spend more time thinking about it. cheers andrew --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers