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 1r7XzR-005mYS-EB for pgsql-general@arkaria.postgresql.org; Mon, 27 Nov 2023 09:33:17 +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 1r7XzP-00C3Gt-TE for pgsql-general@arkaria.postgresql.org; Mon, 27 Nov 2023 09:33:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r7XzP-00C3Gl-Ht for pgsql-general@lists.postgresql.org; Mon, 27 Nov 2023 09:33:15 +0000 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r7XzO-008lGO-3Y for pgsql-general@lists.postgresql.org; Mon, 27 Nov 2023 09:33:14 +0000 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6d81fc0ad6eso706913a34.2 for ; Mon, 27 Nov 2023 01:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701077592; x=1701682392; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SQybT+P9D34i50um+Hr4RORyKvS1Aa4nZDrqZy2UmuE=; b=BHWVsF8pMGcXiKJ7IF9SeMAT/gQMZ0H7jX3Lio8RT2ZII94Ks5147dc9PInXYSosPP v5mu4dELbZHaUeN++dys3GKrKSYcdHhIXafstp98+gGeT34AIFx/Iv0cqj8YDUdNHZgg jM0ISmzJTV6V4oSVXuuWjVqkl70jlbPRxF+KUdUN2AYUFaNeDMLOZKU7Uk33ApDjhHyf Xfvi/pN5HBbQlgskfoT/NmysdzCraFdGzeoLjPOyHq6zy42oRPlIY4W4TlATIwJS5ljN sxP+2onQGEXjjHIzDe3EIYc0C+waDOG9FQGLueXI/BYfu0Qao4xsbl0wgsYJDuCrcz1l L6Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701077592; x=1701682392; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SQybT+P9D34i50um+Hr4RORyKvS1Aa4nZDrqZy2UmuE=; b=Akyq7d230VFywfqbI9kzBVNIZBqkyCEp270iFFpWG0im6OnhjZoESB6PpGOWLoYNn3 abPBcj3rCvNmEoopncju6wWXLFyWfvou8FB6SUmPDe6LxYw0WyWj9tlUFuyUbw0Ju0B/ +z2OTMQBGyVl3hCcWslD814SuToZb6Zfo1wLhmVuLrQ1H3cHK9PdyV6J8lCzgMWwjWD7 JquQKzzqC6cg6VkEbLFDIryT2Mgy3anEclQ7cvRzmOqY3VLab4dGZ9L4U0yFcyuUvjPt r/uhmgl6Eml9L46dUnXekPuu+vtxuCNavbxOoP8wYdWDQrbqHm8AIly7korWvUjlZBcq 7Ncw== X-Gm-Message-State: AOJu0YzbcTyC5rJX/B+iuTVgYKm10o/3D/zzLihxuv+XNGVdqLnWie+I vJDbKU/xdeSbt8ImcrXMtBkm0lYSGk1CckezsA0= X-Google-Smtp-Source: AGHT+IH3WM5sln1Q62lYGlgCNNG9PWkTPItuzJaCE0jg9eyqzGtG6gr2pHNKLUM3xdCz7UYeqwrdHpTmXPIJuXAB5Ww= X-Received: by 2002:a05:6870:658b:b0:1fa:3e11:e16f with SMTP id fp11-20020a056870658b00b001fa3e11e16fmr5144154oab.40.1701077591949; Mon, 27 Nov 2023 01:33:11 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Dominique Devienne Date: Mon, 27 Nov 2023 10:33:00 +0100 Message-ID: Subject: Re: Emitting JSON to file using COPY TO To: Adrian Klaver Cc: Davin Shearer , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000009a83be060b1efdd0" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009a83be060b1efdd0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Nov 25, 2023 at 10:00=E2=80=AFPM Adrian Klaver wrote: > On 11/25/23 11:21, Davin Shearer wrote: > > Hello! > > > > I'm trying to emit a JSON aggregation of JSON rows to a file using COPY > > TO, but I'm running into problems with COPY TO double quoting the > > output. Here is a minimal example that demonstrates the problem I'm > > having: > > > > > I have tried to get COPY TO to copy the results to file "as-is" by > > setting the escape and the quote characters to the empty string (''), > > but they only apply to the CSV format. > > > > Is there a way to emit JSON results to file from within postgres? > > Effectively, nn "as-is" option to COPY TO would work well for this JSON > > use case. > > > > Not using COPY. > > See David Johnson's post for one way using the client psql. > > Otherwise you will need to use any of the many ETL programs out there > that are designed for this sort of thing. > Guys, I don't get answers like that. The JSON spec is clear: > --0000000000009a83be060b1efdd0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sat, Nov 25, 2023 at 10:00=E2=80=AFPM = Adrian Klaver <adrian.klave= r@aklaver.com> wrote:
On 11/25/23 11:21, Davin Shearer wr= ote:
> Hello!
>
> I'm trying to emit a JSON aggregation of JSON rows to a file using= COPY
> TO, but I'm running into problems with COPY TO double quoting the =
> output. =C2=A0 Here is a minimal example that demonstrates the problem= I'm
> having:
>

> I have tried to get COPY TO to copy the results to file "as-is&qu= ot; by
> setting the escape and the quote characters to the empty string ('= '),
> but they only apply to the CSV format.
>
> Is there a way to emit JSON results to file from within postgres?=C2= =A0
> Effectively, nn "as-is" option to COPY TO would work well fo= r this JSON
> use case.
>

Not using COPY.

See David Johnson's post for one way using the client psql.

Otherwise you will need to use any of the many ETL programs out there
that are designed for this sort of thing.

Guys, I don't get answers like that. The JSON spec is clear:

>=C2=A0=C2=A0
--0000000000009a83be060b1efdd0--