Re: BUG #12320: json parsing with embedded double quotes

From: Aaron Botsis <aaron(at)bt-r(dot)com>
To: Francisco Olarte <folarte(at)peoplecall(dot)com>
Cc: postgres(at)bt-r(dot)com, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #12320: json parsing with embedded double quotes
Date: 2015-01-06 18:06:38
Message-ID: 220F46D8-1D35-487F-AFF7-B58A30E4632A@bt-r.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hi Francisco, I’m aware, but still consider this to be a bug, or at least a great opportunity for an enhancement. :)

This had bitten me for the third time while trying to import some json data. It’d be great to bypass the copy escaping (and possibly other meta characters) when the column type is json or jsonb. I’d be happy to try and write it and submit a patch if folks believe this is an acceptable way to go… That said, I should probably read what the process is for this kind of thing :)

Aaron

> On Dec 23, 2014, at 1:17 PM, Francisco Olarte <folarte(at)peoplecall(dot)com> wrote:
>
> Hi Aaron:
> ....
> user:\"root\""}}}}},"from":0,"size":20,"timeout":10000,"sort":{"timestamp":{"order":"
> .....
>
> Copy from does it's own round of backslash scaping, if you look at
>
> http://www.postgresql.org/docs/9.4/static/sql-copy.html <http://www.postgresql.org/docs/9.4/static/sql-copy.html>
>
> The third paragraph under File formats / text format reads:
> Backslash characters (\) can be used in the COPY data to quote data characters that might otherwise be taken as row or column delimiters. In particular, the following characters must be preceded by a backslash if they appear as part of a column value: backslash itself, newline, carriage return, and the current delimiter character.
>
> As you want the backslash as part of the data you need to double it in the file, otherwise you'll fall into the later case:
>
> .....Any other backslashed character that is not mentioned in the above table will be taken to represent itself
>
> And the backslash will get eaten and the json parser will fail. It's the same problem that you get when you try to put windows paths or perl type regular expresions inside doube quoted C/Java/perl/shell/and_many_more Strings.
>
> If your table is always a single column and you cannot edit the file, you can always try to change the scape character.
>
> Regards.
> Francisco Olarte.
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Francisco Olarte 2015-01-06 18:52:28 Re: BUG #12320: json parsing with embedded double quotes
Previous Message Sandeep Thakkar 2015-01-06 11:23:22 Re: BUG #12328: can't install the postgresql

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2015-01-06 18:25:24 Re: Transactions involving multiple postgres foreign servers
Previous Message Robert Haas 2015-01-06 17:39:12 Re: INSERT ... ON CONFLICT UPDATE and RLS