pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aaron Botsis <aaron@bt-r.com>
To: Andrew Dunstan <andrew@dunslane.net>
To: pgsql-hackers@postgresql.org
Cc: Francisco Olarte <folarte@peoplecall.com>
Subject: Re: Patch: [BUGS] BUG #12320: json parsing with embedded double quotes
Date: Fri, 9 Jan 2015 12:57:31 -0500
Message-ID: <5BE71065-CCF8-4262-8762-D23CB1118BD0@bt-r.com> (raw)
In-Reply-To: <54B003BF.3090306@dunslane.net>
References: <CA+bJJbz2EfCb-7OyizwE8e3b9MnZy9kyKkEdwrfdZ+aVsYCfog@mail.gmail.com>
	<87B56448-146A-4ECD-96D3-8B09B89D4EEA@bt-r.com>
	<54AD8CEF.3080904@dunslane.net>
	<D58AB253-3AE9-48DF-BD6F-B8F9BA979DDB@bt-r.com>
	<54AEEC3C.10907@dunslane.net>
	<E4532EA7-503E-4E18-917A-97DA12C4E82B@bt-r.com>
	<54B003BF.3090306@dunslane.net>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>


> On Jan 9, 2015, at 11:37 AM, Andrew Dunstan <andrew@dunslane.net> wrote:
> 
> 
> On 01/08/2015 08:42 PM, Aaron Botsis wrote:
>> 
>>> On Jan 8, 2015, at 3:44 PM, Andrew Dunstan <andrew@dunslane.net> wrote:
>>> 
>>> 
>>> On 01/08/2015 03:05 PM, Aaron Botsis wrote:
>>>> 
>>>>> It's also unnecessary. CSV format, while not designed for this, is nevertheless sufficiently flexible to allow successful import of json data meeting certain criteria (essentially no newlines), like this:
>>>>> 
>>>>>  copy the_table(jsonfield)
>>>>>  from '/path/to/jsondata'
>>>>>  csv quote e'\x01' delimiter e'\x02’;
>>>> While perhaps unnecessary, given the size and simplicity of the patch, IMO it’s a no brainer to merge (it actually makes the code smaller by 3 lines). It also enables non-json use cases anytime one might want to preserve embedded escapes, or use different ones entirely. Do you see other reasons not to commit it?
>>> 
>>> Well, for one thing it's seriously incomplete. You need to be able to change the delimiter as well. Otherwise, any embedded tab in the json will cause you major grief.
>>> 
>>> Currently the delimiter and the escape MUST be a single byte non-nul character, and there is a check for this in csv mode. Your patch would allow any arbitrary string (including one of zero length) for the escape in text mode, 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 tend to be VERY cautious about making changes. This is a fairly fragile ecosystem.
>> 
>> So I’m 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 break it let me know and I’ll make sure to add regression tests for them as well.
>> 
> Well, I still need convincing that this is the best solution to the problem. As I said, I need to spend more time thinking about it.


I offered an alternative (RAW mode w/record terminator) that you ignored. So in lieu of a productive discussion about “the best solution to the problem”, I went ahead and continued to complete the patch since I believe it’s a useful FE that it could be helpful for this and other use cases. There have been multiple times (not even w/json) I wished COPY would stop being so smart. 

FWIW, (if anyone’s interested in it) I also hacked up some python that’ll read a json file, and outputs a binary file suitable for use with COPY BINARY that gets around all this stuff. Obviously this only works for json (not jsonb) columns (though you could SELECT INTO a jsonb column). Happy to pass it along.

Aaron

view thread (9+ messages)  latest in thread

Message-ID: <5BE71065-CCF8-4262-8762-D23CB1118BD0@bt-r.com>
Permalink:  ../5BE71065-CCF8-4262-8762-D23CB1118BD0@bt-r.com/
Also on:    postgresql.org/message-id/5BE71065-CCF8-4262-8762-D23CB1118BD0@bt-r.com

 · 

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: aaron@bt-r.com, andrew@dunslane.net, pgsql-hackers@postgresql.org, folarte@peoplecall.com
  Subject: Re: Patch: [BUGS] BUG #12320: json parsing with embedded double quotes
  In-Reply-To: <5BE71065-CCF8-4262-8762-D23CB1118BD0@bt-r.com>
  References: <CA+bJJbz2EfCb-7OyizwE8e3b9MnZy9kyKkEdwrfdZ+aVsYCfog@mail.gmail.com> <87B56448-146A-4ECD-96D3-8B09B89D4EEA@bt-r.com> <54AD8CEF.3080904@dunslane.net> <D58AB253-3AE9-48DF-BD6F-B8F9BA979DDB@bt-r.com> <54AEEC3C.10907@dunslane.net> <E4532EA7-503E-4E18-917A-97DA12C4E82B@bt-r.com> <54B003BF.3090306@dunslane.net> <5BE71065-CCF8-4262-8762-D23CB1118BD0@bt-r.com>

* 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