Re: Emitting JSON to file using COPY TO

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Joe Conway <mail(at)joeconway(dot)com>, 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 12:41:20
Message-ID: 9c77b6fa-ee88-b2e6-0fa7-4fc81721da35@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers


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.

cheers

andrew

>
>
--
Andrew Dunstan
EDB: https://www.enterprisedb.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2023-12-04 13:37:23 Re: Emitting JSON to file using COPY TO
Previous Message David Rowley 2023-12-04 02:57:20 Re: vacuum visibility relevance

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2023-12-04 12:49:57 Rename ShmemVariableCache and initialize it in more standard way
Previous Message Dean Rasheed 2023-12-04 12:14:42 Adding OLD/NEW support to RETURNING