From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Davin Shearer <davin(at)apache(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Emitting JSON to file using COPY TO |
Date: | 2023-12-05 02:54:50 |
Message-ID: | cbd65026-d79c-40b1-8be3-10e1db2fc092@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On 12/4/23 17:55, Davin Shearer wrote:
> Sorry about the top posting / top quoting... the link you sent me gives
> me a 404. I'm not exactly sure what top quoting / posting means and
> Googling those terms wasn't helpful for me, but I've removed the quoting
> that my mail client is automatically "helpfully" adding to my emails. I
> mean no offense.
No offense taken. But it is worthwhile to conform to the very long
established norms of the mailing lists on which you participate. See:
https://en.wikipedia.org/wiki/Posting_style
I would describe the Postgres list style (based on that link) as
"inline replying, in which the different parts of the reply follow
the relevant parts of the original post...[with]...trimming of the
original text"
> There are however a few characters that need to be escaped
> 1. |"|(double quote)
> 2. |\|(backslash)
> 3. |/|(forward slash)
> 4. |\b|(backspace)
> 5. |\f|(form feed)
> 6. |\n|(new line)
> 7. |\r|(carriage return)
> 8. |\t|(horizontal tab)
>
> These characters should be represented in the test cases to see how the
> escaping behaves and to ensure that the escaping is done properly per
> JSON requirements.
I can look at adding these as test cases. The latest version of the
patch (attached) includes some of that already. For reference, the tests
so far include this:
8<-------------------------------
test=# select * from copytest;
style | test | filler
---------+----------+--------
DOS | abc\r +| 1
| def |
Unix | abc +| 2
| def |
Mac | abc\rdef | 3
esc\ape | a\r\\r\ +| 4
| \nb |
(4 rows)
test=# copy copytest to stdout (format json);
{"style":"DOS","test":"abc\r\ndef","filler":1}
{"style":"Unix","test":"abc\ndef","filler":2}
{"style":"Mac","test":"abc\rdef","filler":3}
{"style":"esc\\ape","test":"a\\r\\\r\\\n\\nb","filler":4}
8<-------------------------------
At this point "COPY TO" should be sending exactly the unaltered output
of the postgres JSON processing functions.
--
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Attachment | Content-Type | Size |
---|---|---|
copyto_json.004.diff | text/x-patch | 18.8 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2023-12-05 14:56:03 | Re: Emitting JSON to file using COPY TO |
Previous Message | Tom Lane | 2023-12-05 00:43:07 | Re: Help understand why DELETE is so slow |
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Geoghegan | 2023-12-05 03:25:55 | Re: Optimizing nbtree ScalarArrayOp execution, allowing multi-column ordered scans, skip scan |
Previous Message | Kyotaro Horiguchi | 2023-12-05 02:43:42 | Re: gai_strerror() is not thread-safe on Windows |