| From: | Joe Conway <mail(at)joeconway(dot)com> | 
|---|---|
| To: | Andrew Dunstan <andrew(at)dunslane(dot)net>, Davin Shearer <davin(at)apache(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Re: Emitting JSON to file using COPY TO | 
| Date: | 2023-12-04 13:37:23 | 
| Message-ID: | c30fc5da-0348-4e44-b699-804ccbdcfc36@joeconway.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general pgsql-hackers | 
On 12/4/23 07:41, Andrew Dunstan wrote:
> 
> On 2023-12-03 Su 20:14, Joe Conway wrote:
>> (please don't top quote on the Postgres lists)
>>
>> On 12/3/23 17:38, Davin Shearer wrote:
>>> " being quoted as \\" breaks the JSON. It needs to be \".  This has 
>>> been my whole problem with COPY TO for JSON.
>>>
>>> Please validate that the output is in proper format with correct 
>>> quoting for special characters. I use `jq` on the command line to 
>>> validate and format the output.
>>
>> I just hooked existing "row-to-json machinery" up to the "COPY TO" 
>> statement. If the output is wrong (just for for this use case?), that 
>> would be a missing feature (or possibly a bug?).
>>
>> Davin -- how did you work around the issue with the way the built in 
>> functions output JSON?
>>
>> Andrew -- comments/thoughts?
> 
> I meant to mention this when I was making comments yesterday.
> 
> The patch should not be using CopyAttributeOutText - it will try to
> escape characters such as \, which produces the effect complained of
> here, or else we need to change its setup so we have a way to inhibit
> that escaping.
Interesting.
I am surprised this has never been raised as a problem with COPY TO before.
Should the JSON output, as produced by composite_to_json(), be sent 
as-is with no escaping at all? If yes, is JSON somehow unique in this 
regard?
-- 
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrew Dunstan | 2023-12-04 14:25:04 | Re: Emitting JSON to file using COPY TO | 
| Previous Message | Andrew Dunstan | 2023-12-04 12:41:20 | Re: Emitting JSON to file using COPY TO | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | John Naylor | 2023-12-04 13:38:53 | Re: Move bki file pre-processing from initdb - part 1 - initdb->genbki.pl | 
| Previous Message | zhihuifan1213 | 2023-12-04 12:55:05 | Re: Avoid detoast overhead when possible |