Re: Maintaining accents with "COPY" ? - Mailing list pgsql-general

From Erik Wienhold
Subject Re: Maintaining accents with "COPY" ?
Date
Msg-id 1917340025.188822.1685000906999@office.mailbox.org
Whole thread Raw
In response to Maintaining accents with "COPY" ?  (Laura Smith <n5d9xq3ti233xiyif2vp@protonmail.ch>)
Responses Re: Maintaining accents with "COPY" ?
List pgsql-general
> On 25/05/2023 09:14 CEST Laura Smith <n5d9xq3ti233xiyif2vp@protonmail.ch> wrote:
>
> I'm currently doing a CSV export using COPY:
>
> COPY (select * from foo where bar='foo') TO '/tmp/bar.csv' DELIMITER ',' CSV HEADER;
>
> This works great apart from accents are not preserved in the output, for
> example é gets converted to random characters, e.g. √© or similar.
>
> How can I preserve accents ?

Looks like an encoding issue and a mismatch between database encoding and client
encoding.  You can check both with:

    SHOW server_encoding;
    SHOW 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):

    SET client_encoding = 'utf8';
    COPY (...) TO /tmp/bar.csv DELIMITER ',' CSV HEADER ENCODING 'utf8';

--
Erik



pgsql-general by date:

Previous
From: Laura Smith
Date:
Subject: Maintaining accents with "COPY" ?
Next
From: Laura Smith
Date:
Subject: Re: Maintaining accents with "COPY" ?