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 1qrQEC-004Clr-Kn for pgsql-general@arkaria.postgresql.org; Fri, 13 Oct 2023 22:01:52 +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 1qrQEA-00401S-FI for pgsql-general@arkaria.postgresql.org; Fri, 13 Oct 2023 22:01:51 +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 1qrQEA-004013-3m for pgsql-general@lists.postgresql.org; Fri, 13 Oct 2023 22:01:50 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qrQE6-000QAD-9R for pgsql-general@postgresql.org; Fri, 13 Oct 2023 22:01:50 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 39DM1hNi1593974; Fri, 13 Oct 2023 18:01:43 -0400 From: Tom Lane To: Greig Wise cc: pgsql-general@postgresql.org Subject: Re: JSON fields with backslashes In-reply-to: References: Comments: In-reply-to Greig Wise message dated "Fri, 13 Oct 2023 17:51:31 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1593972.1697234503.1@sss.pgh.pa.us> Date: Fri, 13 Oct 2023 18:01:43 -0400 Message-ID: <1593973.1697234503@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Greig Wise writes: > Hello. I have run into an issue when using the copy command on tables > with json columns where Postgres seems to improperly escape backslashes > under certain conditions thus creating invalid JSON. AFAICS this is COPY's normal behavior: it doubles backslashes in the default format. You could use CSV format, perhaps, but that has its own quoting rules that also mean that what comes out is not going to be json-and-nothing-but. See "File Formats" here: https://www.postgresql.org/docs/current/sql-copy.html regards, tom lane