Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r9v7W-003Hc7-DN for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Dec 2023 22:39:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r9v7U-00DbjG-3W for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Dec 2023 22:39:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r9v7T-00Dbj7-Oq for pgsql-hackers@lists.postgresql.org; Sun, 03 Dec 2023 22:39:23 +0000 Received: from mxout1-he-de.apache.org ([95.216.194.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r9v7Q-008eNj-OT for pgsql-hackers@postgresql.org; Sun, 03 Dec 2023 22:39:22 +0000 Received: from mail.apache.org (mailgw-he-de.apache.org [IPv6:2a01:4f8:c2c:d4aa::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mxout1-he-de.apache.org (ASF Mail Server at mxout1-he-de.apache.org) with ESMTPS id 6CCFF61C15 for ; Sun, 3 Dec 2023 22:38:42 +0000 (UTC) Received: (qmail 913457 invoked by uid 116); 3 Dec 2023 22:38:42 -0000 Received: from mailrelay1-he-de.apache.org (HELO mailrelay1-he-de.apache.org) (116.203.21.61) by apache.org (qpsmtpd/0.94) with ESMTP; Sun, 03 Dec 2023 22:38:42 +0000 Authentication-Results: apache.org; auth=none Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mailrelay1-he-de.apache.org (ASF Mail Server at mailrelay1-he-de.apache.org) with ESMTPSA id C59AA40EF4 for ; Sun, 3 Dec 2023 22:38:41 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5c6839373f8so289451a12.0 for ; Sun, 03 Dec 2023 14:38:41 -0800 (PST) X-Gm-Message-State: AOJu0YxE3u1SdB+vZd8y6H6X/EbjVV0crQguOrAUpNX2LqLmpGEwTeIn +16YfYPPHs5sCJe4J6ksU8yyWy7s3yZCc+8VpMA= X-Google-Smtp-Source: AGHT+IGCjElRh1OotifvYfVRHUvMytt387Qsu+z4BthuVR/XmAnwoDNPQz3krNZhb8fTbV/d4FSd+/R82OsDFxatGJI= X-Received: by 2002:a17:90b:4a8e:b0:286:ab7f:af5e with SMTP id lp14-20020a17090b4a8e00b00286ab7faf5emr805997pjb.24.1701643119895; Sun, 03 Dec 2023 14:38:39 -0800 (PST) MIME-Version: 1.0 References: <3853387.1701096982@sss.pgh.pa.us> <3a98decf-3fe3-4b49-9b68-fda01338872c@sedlakovi.org> <24e3ee88-ec1e-421b-89ae-8a47ee0d2df1@joeconway.com> <7117a356-916c-4cf3-bad8-861490e65dcf@joeconway.com> In-Reply-To: <7117a356-916c-4cf3-bad8-861490e65dcf@joeconway.com> From: Davin Shearer Date: Sun, 3 Dec 2023 17:38:28 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Emitting JSON to file using COPY TO To: Joe Conway , PostgreSQL-development , Andrew Dunstan Content-Type: multipart/alternative; boundary="000000000000b22d6c060ba2a9af" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b22d6c060ba2a9af Content-Type: text/plain; charset="UTF-8" " 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. On Sun, Dec 3, 2023, 10:51 Joe Conway wrote: > On 12/3/23 10:31, Davin Shearer wrote: > > Please be sure to include single and double quotes in the test values > > since that was the original problem (double quoting in COPY TO breaking > > the JSON syntax). > > test=# copy (select * from foo limit 4) to stdout (format json); > {"id":2456092,"f1":"line with ' in it: > 2456092","f2":"2023-12-03T10:44:40.9712-05:00"} > {"id":2456093,"f1":"line with \\" in it: > 2456093","f2":"2023-12-03T10:44:40.971221-05:00"} > {"id":2456094,"f1":"line with ' in it: > 2456094","f2":"2023-12-03T10:44:40.971225-05:00"} > {"id":2456095,"f1":"line with \\" in it: > 2456095","f2":"2023-12-03T10:44:40.971228-05:00"} > > -- > Joe Conway > PostgreSQL Contributors Team > RDS Open Source Databases > Amazon Web Services: https://aws.amazon.com > > --000000000000b22d6c060ba2a9af Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
" being quoted as \\" breaks the JSON. It needs= to be \".=C2=A0 This has been my whole problem with COPY TO for JSON.=

Please validate that the outp= ut is in proper format with correct quoting for special characters. I use `= jq` on the command line to validate and format the output.=C2=A0

On Su= n, Dec 3, 2023, 10:51 Joe Conway <= mail@joeconway.com> wrote:
O= n 12/3/23 10:31, Davin Shearer wrote:
> Please be sure to include single and double quotes in the test values =
> since that was the original problem (double quoting in COPY TO breakin= g
> the JSON syntax).

test=3D# copy (select * from foo limit 4) to stdout (format json);
{"id":2456092,"f1":"line with ' in it:
2456092","f2":"2023-12-03T10:44:40.9712-05:00"} {"id":2456093,"f1":"line with \\" in it:
2456093","f2":"2023-12-03T10:44:40.971221-05:00"}<= br> {"id":2456094,"f1":"line with ' in it:
2456094","f2":"2023-12-03T10:44:40.971225-05:00"}<= br> {"id":2456095,"f1":"line with \\" in it:
2456095","f2":"2023-12-03T10:44:40.971228-05:00"}<= br>
--
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

--000000000000b22d6c060ba2a9af--