pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #13160: Incorrect escaping of quotes in JSON export
2+ messages / 2 participants
[nested] [flat]
* BUG #13160: Incorrect escaping of quotes in JSON export
@ 2015-04-25 19:53 me@andrewray.me
2015-04-27 16:12 ` Re: BUG #13160: Incorrect escaping of quotes in JSON export Marko Tiikkaja <marko@joh.to>
0 siblings, 1 reply; 2+ messages in thread
From: me@andrewray.me @ 2015-04-25 19:53 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 13160
Logged by: Andy
Email address: me@andrewray.me
PostgreSQL version: 9.3.5
Operating system: OSX
Description:
Postgres escapes quotes incorrectly when creating a JSON export.
UPDATE models SET column='"hello"' WHERE id=1;
COPY (SELECT row_to_json(models)
FROM (SELECT column FROM shaders WHERE id=1) shaders)
TO '/output.json';
The contents of output.json:
{"column":"\\"hello\\""}
You can see that the quotes are escaped improperly and it creates invalid
JSON.
It should be:
{"column":"\"hello\""}
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #13160: Incorrect escaping of quotes in JSON export
2015-04-25 19:53 BUG #13160: Incorrect escaping of quotes in JSON export me@andrewray.me
@ 2015-04-27 16:12 ` Marko Tiikkaja <marko@joh.to>
0 siblings, 0 replies; 2+ messages in thread
From: Marko Tiikkaja @ 2015-04-27 16:12 UTC (permalink / raw)
To: me@andrewray.me; pgsql-bugs
On 4/25/15 9:53 PM, me@andrewray.me wrote:
> Postgres escapes quotes incorrectly when creating a JSON export.
>
> UPDATE models SET column='"hello"' WHERE id=1;
>
> COPY (SELECT row_to_json(models)
> FROM (SELECT column FROM shaders WHERE id=1) shaders)
> TO '/output.json';
>
> The contents of output.json:
>
> {"column":"\\"hello\\""}
>
> You can see that the quotes are escaped improperly and it creates invalid
> JSON.
It's not supposed to create valid JSON. It's supposed to generate
something which can be COPYed back into a database. From the COPY
documentation page:
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.
> It should be:
>
> {"column":"\"hello\""}
That doesn't COPY back in:
=# \copy qwr from /tmp/foo
ERROR: invalid input syntax for type json
DETAIL: Token "hello" is invalid.
CONTEXT: JSON data, line 1: {"column":""hello...
COPY qwr, line 1, column a: "{"column":""hello""}"
COPY currently doesn't support what you're trying to do. I suggest
using a simple program which connects to the database and writes the
result column into a file verbatim.
.m
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2015-04-27 16:12 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-04-25 19:53 BUG #13160: Incorrect escaping of quotes in JSON export me@andrewray.me
2015-04-27 16:12 ` Marko Tiikkaja <marko@joh.to>
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