Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q25iF-0007oC-7p for pgsql-general@arkaria.postgresql.org; Thu, 25 May 2023 07:48:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q25iE-0000l4-62 for pgsql-general@arkaria.postgresql.org; Thu, 25 May 2023 07:48:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q25iD-0000kv-S0 for pgsql-general@lists.postgresql.org; Thu, 25 May 2023 07:48:41 +0000 Received: from mout-u-204.mailbox.org ([2001:67c:2050:101:465::204]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q25iA-001mV0-NX for pgsql-general@lists.postgresql.org; Thu, 25 May 2023 07:48:40 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4QRgCb3fDkz9sQc; Thu, 25 May 2023 09:48:27 +0200 (CEST) Date: Thu, 25 May 2023 09:48:26 +0200 (CEST) From: Erik Wienhold To: Laura Smith , postgre Message-ID: <1917340025.188822.1685000906999@office.mailbox.org> In-Reply-To: References: Subject: Re: Maintaining accents with "COPY" ? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 25/05/2023 09:14 CEST Laura Smith = wrote: > > I'm currently doing a CSV export using COPY: > > COPY (select * from foo where bar=3D'foo') TO '/tmp/bar.csv' DELIMITER ',= ' CSV HEADER; > > This works great apart from accents are not preserved in the output, for > example =C3=A9 gets converted to random characters, e.g. =E2=88=9A=C2=A9 = or similar. > > How can I preserve accents ? Looks like an encoding issue and a mismatch between database encoding and c= lient encoding. You can check both with: =09SHOW server_encoding; =09SHOW client_encoding; Then either set the client encoding or use COPY's encoding option to match = the database encoding (I assume utf8 in this example): =09SET client_encoding =3D 'utf8'; =09COPY (...) TO /tmp/bar.csv DELIMITER ',' CSV HEADER ENCODING 'utf8'; -- Erik