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 1r7seF-007FA7-Io for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2023 07:36:47 +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 1r7seB-003DGp-Pz for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2023 07:36:43 +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 1r7seB-003DGB-Dr for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2023 07:36:43 +0000 Received: from sender-op-o9.zoho.eu ([136.143.169.9]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r7se8-008vmi-Ld for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2023 07:36:42 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1701156994; cv=none; d=zohomail.eu; s=zohoarc; b=N43HUGYcF3lPz0ncb0EyZ79wBC4yHs2iPJpPpCJSMrkK5BKDJvNwIOaNtHuXifAFzSrEt5+XDYaiLyTneMpj8JFq0vmIZuqihgJFw12q2mKyngFNW2opAhPKdp13sWaIXpEp0XvNEwEOGOIzIchmxwEaj5XWfP927DoqAloRuIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1701156994; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=FVKIYyfWndcZL82IPyGfsVHQxCObxXw1stzFRjhAna4=; b=dsS+V6UJXjqc/iGrH33rcZ5aFGaXYQX7fyGCQqzgBi/c9471Ls7EFrBgb8xTa/XhqdKG92hfObWzND1HzKwGRZ2AIAFbNCLtpqElU89f3AFJp6gOZH3wJpHC61zcWjneZPWQYEyHDfPlgqJOOcaVRr+HR1ejVss+Nhsn1QhSfME= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=sedlakovi.org; spf=pass smtp.mailfrom=filip@sedlakovi.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1701156994; s=admin; d=sedlakovi.org; i=filip@sedlakovi.org; h=Message-ID:Date:Date:MIME-Version:Subject:Subject:To:To:Cc:Cc:References:From:From:In-Reply-To:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=FVKIYyfWndcZL82IPyGfsVHQxCObxXw1stzFRjhAna4=; b=fUjX/Iu1hQ7AP8wJGdhkAt6v5QsigNXUS3JVYEs2ItS/CwYHoUOCH9vaG6A59dgf vbDpqVvy4ZUxlwTuM+4RYKptkmVm6YkBoxdoVeIdIMYVIOl0CypE/Pa/lw+5BPBJgHR Ao9vSuRvfCNEZ4nBVfogPRJkZQzxhB65RsytUffg= Received: from [192.168.1.28] (ip-213-220-240-128.bb.vodafone.cz [213.220.240.128]) by mx.zoho.eu with SMTPS id 1701156992945214.17207536700573; Tue, 28 Nov 2023 08:36:32 +0100 (CET) Message-ID: <3a98decf-3fe3-4b49-9b68-fda01338872c@sedlakovi.org> Date: Tue, 28 Nov 2023 08:36:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Emitting JSON to file using COPY TO To: Dominique Devienne , Tom Lane Cc: "David G. Johnston" , Adrian Klaver , Davin Shearer , "pgsql-general@lists.postgresql.org" References: <3853387.1701096982@sss.pgh.pa.us> Content-Language: en-US From: =?UTF-8?Q?Filip_Sedl=C3=A1k?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ZohoMailClient: External List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This would be a very special case for COPY. It applies only to a single column of JSON values. The original problem can be solved with psql --tuples-only as David wrote earlier. $ psql -tc 'select json_agg(row_to_json(t)) from (select * from public.tbl_json_test) t;' [{"id":1,"t_test":"here's a \"string\""}] Special-casing any encoding/escaping scheme leads to bugs and harder parsing. Just my 2c. -- Filip Sedlák