0

I use COPY to import a file in my database

COPY mytable(c1, c2) FROM '/tmp/myfile.csv' WITH DELIMITER ';' CSV HEADER

And as usual, there are some "bad" caracters in the file wich generates encoding SQL error:

ERROR:  invalid byte sequence for encoding "UTF8": 0xdf 0x4f

So I open the file and delete the line but, is there a way to COPY a file excluding by default this kind of line ?

Thanks for help

Macbernie
  • 1,303
  • 6
  • 24
  • 48
  • Possible duplicate of [invalid byte sequence for encoding "UTF8"](http://stackoverflow.com/questions/4867272/invalid-byte-sequence-for-encoding-utf8) – Lukasz Szozda Nov 09 '15 at 11:19
  • There are no bad characters, just badly applied encodings or incorrect code sequences. Is your file actually in UTF-8? If it was Windows-1252, for example, `0xdf 0x4f` is the sequence "ßO", which is not impossible if your source file contains German. – Jeroen Mostert Nov 09 '15 at 11:48
  • Yes but, I just want to know if I can exclude this line ? – Macbernie Nov 09 '15 at 11:51
  • 1
    There's no built in way to skip lines with errors in PostgreSQL's `COPY`, at least in 9.5 and older. Filter it with an external program, use a script, use an ETL tool, etc. – Craig Ringer Nov 10 '15 at 05:17

0 Answers0