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 1r6zlP-003Wcb-SE for pgsql-general@arkaria.postgresql.org; Sat, 25 Nov 2023 21:00:32 +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 1r6zlO-0051CS-6b for pgsql-general@arkaria.postgresql.org; Sat, 25 Nov 2023 21:00:30 +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 1r6zlM-0051CJ-BU for pgsql-general@lists.postgresql.org; Sat, 25 Nov 2023 21:00:29 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6zlE-008Vmd-EN for pgsql-general@lists.postgresql.org; Sat, 25 Nov 2023 21:00:27 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id AD9AF3200B8D; Sat, 25 Nov 2023 16:00:15 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sat, 25 Nov 2023 16:00:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1700946015; x=1701032415; bh=QS10OSjdxI4QZE4xfbjzWPmWMmXqlEbc/J/ AnOWWFaY=; b=V2Q0psJ0NIUFwXLSw8dAWRogDT0rw1/dG/KRf29FWt7ryDSX11l GnuVoV2ihazHh0DuQ0bgMyo+iRx638Bu2AAVBqIpvVPZzIdAwAE+0VL5GumDPhim SQURMfRtQGpzHgQdADrmq8HxnixUANb4yfGWvAF794HQ3mBKdWt4v+tpkUv9KCQ8 uPIaKSrRPirCMnuct0Dq+93ibYFns9ql/CFVibOaU7x1h45uSJ8eDRWQLmv4U+Xy dO8mk6tdSYr8CYpqYPWTsX3aQj1inyRRqY7UAZJzmdLRL29dKmWFeEVP27MgReDo bIo9PGmcG5ZaKyNWSZrLqVrsCZ8/liT/j5Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1700946015; x= 1701032415; bh=QS10OSjdxI4QZE4xfbjzWPmWMmXqlEbc/J/AnOWWFaY=; b=C GnetibT398WK80hA6AFHL64jyKrPTsyVLKTkWsyDQkSlPneUe+JWbKj0cBs9X359 xkbDIa1VsR6//Abab/GVNGj2QtdkpvRrU3VVcDDK0NEBh+MlYOFUFL3jcKj7EVGJ d5+oZ/Gyjgm5MW2NiL6OadWGPNXpi2+sUH9Z9OYjOc/1kC6bjF615V3ixpXh2fQk gC2w9kL/POkU3J9QaM5KWF5xHt9WNgrzilhB7LTKtLnY8tSegIu7we8FlWxZfupr FXvBmgWunTMotWZ/BZv5QWH6MwQs4/ICXrfGz7km1NxJfa3UFL4/DjsNQ7tZFg5Z zz+sZaNsJxS+iSb06i8/w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudehjedgudegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesth ekredttddvjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeffleegie efgfevudehtdfhkeeutdffjeevgeffgeejvedthefgudeiteefheejheenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrg hvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 25 Nov 2023 16:00:14 -0500 (EST) Message-ID: Date: Sat, 25 Nov 2023 13:00:12 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Emitting JSON to file using COPY TO To: Davin Shearer , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. > Any assistance would be appreciated. > > Thanks, > Davin -- Adrian Klaver adrian.klaver@aklaver.com