Re: Maintaining accents with "COPY" ?

From: Erik Wienhold <ewie(at)ewie(dot)name>
To: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Maintaining accents with "COPY" ?
Date: 2023-05-25 12:23:50
Message-ID: 1398526026.221236.1685017430977@office.mailbox.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On 25/05/2023 13:26 CEST Peter J. Holzer <hjp-pgsql(at)hjp(dot)at> wrote:
>
> On 2023-05-25 07:14:40 +0000, Laura Smith 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 do you check the output?
>
> If a single character is turned into 2 or 3 characters the issue is
> usually that the program which produces the output (in the case of COPY
> I think that would be the PostgreSQL server, not the client) produces
> UTF-8, but the program consuming it expects an 8-bit character set
> (typically windows-1252). See if oyu can tell that program that the file
> is in UTF-8.
>
> > How can I preserve accents ?
>
> They probably already are preserved.

You're right. The bytes are probably interpreted as Mac OS Roman:

$ echo é | iconv -f macintosh
é
$ echo -n é | xxd
00000000: c3a9

--
Erik

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erik Wienhold 2023-05-25 12:37:18 Re: Maintaining accents with "COPY" ?
Previous Message Tomas Vondra 2023-05-25 12:00:09 Re: Question regarding specifics of GIN and pg_trgm performance and potential use of show_trgm to improve it