0

In this post it's outlined how to copy the contents from a csv in a .gzip file into a postgresql table: Importing zipped CSV file into PostgreSQL.

copy tp from program 'zcat /tmp/tp.csv.gz';

My question is whether it's possible to also convert the encoding of the csv file within the gzip, as shown here invalid byte sequence for encoding "UTF8"

so something like this:

copy tp from program 'iconv -f original_charset -t utf-8 zcat /tmp/tp.csv.gz > stdin';

I get the following error when applying copy from with zcat:

psycopg2.errors.CharacterNotInRepertoire: invalid byte sequence for encoding "UTF8": 0xba CONTEXT: COPY tp, line 677117

When unpacked the csv file is encoded as ASCII

file tp.csv

1 Answer 1

1

Just figure out the encoding of the file, then go

COPY tp FROM PROGRAM 'zcat /tmp/tp.csv.gz' (ENCODING 'whatever');
Sign up to request clarification or add additional context in comments.

1 Comment

thank you Laurenz, the following worked for me with ASCII encoding (which I read should be a subset of UTF8, nonetheless it gave an error): COPY tp FROM PROGRAM 'zcat /tmp/tp.csv.gz' (ENCODING 'latin9');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.