Search code examples
postgresqlpostgresql-copy

PostgreSQL invalid byte sequence for encoding utf8 0xbf


I am importing a CSV file which is related to the properties. It has /n between the values. While trying to import it into a table, the following error shows up:

PostgreSQL invalid byte sequence for encoding utf8 0xbf

I tried by simply importing the single column only, but it is not working. Column values will look like this:

"Job No 305385917-001: To attached Garage (Single remain).\n10305 - 132 STREET NW
Plan 23AF Blk 84 Lot 14\n2002995 LERTA LTD O/A LIR HOMES DONTON\nHENORA"

I want to import the above whole into a single column.

COPY edmonton.general_filtered (descriptive)
FROM 'D:/property_own/descriptive_details.csv'
DELIMITER ',' CSV HEADER;

Solution

  • Your COPY statement is correct, but your data are not in UTF8 encoding.

    They are probably in Latin-1 or Windows-1252, where 0xBF is ¿.

    Specify the encoding correctly, e.g.:

    COPY edmonton.general_filtered (descriptive)
    FROM 'D:/property_own/descriptive_details.csv'
    (FORMAT 'csv', HEADER, ENCODING 'WIN1252');