postgres COPY FROM STDIN WITH encoding error with UTF8 by using libpq

106 Views Asked by At

I created database by following command:

CREATE DATABASE myendb
ENCODING 'UTF-8' 
LC_COLLATE 'en_US.UTF-8'
LC_CTYPE 'en_US.UTF-8'
TEMPLATE template0;

I tried to insert Cyrillic symbols encoding by UTF8 into a table by following copy command by calling PQputCopy..() functions and I got following error:

COPY  my_table_name(columns list)
FROM STDIN WITH  CSV DELIMITER AS ';' NULL AS  E'' QUOTE '"' failed.


EOF:0 Message:ERROR:  value too long for type character(15)
                                            

And I tried to add "ENCODING UTF8" into cmd, I got another error:

 COPY   my_table_name(columns list) 
 FROM STDIN WITH  CSV DELIMITER AS ';' NULL AS  E'' QUOTE '"'  ENCODING 'UTF8' failed.


EOF:0 Message:ERROR:  character with byte sequence 0xd0 0xbb in encoding "UTF8" has no equivalent in encoding "WIN1252"

I load Cyrillic sentence encoding by UTF8. The database also created with encoding UTF8. Character set also set as UTF8. I use libpq to connect and perform copy commands. Where no any WIN1252... Also I tried to add 'set client_encoding='utf8'' - it does not help. I don't know how resolve this... Thank you for help!

1

There are 1 best solutions below

1
On

There are 2 databases in on server. Default database has encoding WIN1252. Another database has encoding UTF8. I tried to connect to non-default database with UTF8. But libpq connects to default database, despite of that I defined database name on connection string. This happens, because I used empty password. I should use for password parameter empty quoted string like as - password=''

the solution here: Postgresql PQconnectdb incorrectly connect to another database, why?