Search code examples
windowspostgresqlpsql

psql on windows: ERROR: invalid byte sequence for encoding "UTF8": 0xc8 0x20


on database1:

  • show LC_CTYPE; shows C
  • show LC_COLLATE; shows C
  • show SERVER_ENCODING; shows UTF8

but set "PGPASSWORD=password1" & set "PGCLIENTENCODING=UTF8" & psql.exe -h 127.0.0.1 -p 5432 -U postgres -d database1 -c "INSERT INTO table1 (column1) VALUES ('mise à jour 1');"

shows: ERROR: invalid byte sequence for encoding "UTF8": 0xc8 0x20

the error disappears if PGCLIENTENCODING is set to ISO_8859_5 for example

how to fix this issue?


Solution

  • There is nothing much to fix. Your Windows shell uses a different encoding than UTF-8, so you have to set the client encoding to that encoding to make it work. To find out which client encoding to use, you must figure out which encoding your shell uses. That in turn depends on which shell you are using and how the Windows system was configured.