Installed the latest version of PostgreSQL on my Windows 10 machine. Created this SQL query to copy data from csv to table:
COPY schema.table(column1, column2)
FROM 'C:\Users\User\Desktop\cyrillic name\cyrillic name.csv'
DELIMITER ',';
Executed it in DataGrip and got this:
[58P01] ERROR: could not open file "C:\Users\User\Desktop\cyrillic name\cyrillic name.csv" for reading: No such file or directory
At the same time if I put this file in 'C:\Users\Public\Postgres\English name.csv', then everything runs perfectly fine. Network service has total control over the cyrillic directory and the file (changed it after I got "Permission denied" when file was under fully english path in my desktop folder (C:\Users\User\Desktop)). Found this answer and decided to use \copy in psql:
postgres-# cmd.exe /c chcp 1252
postgres-# \COPY schema.table(column1, column2) FROM 'C:\Users\User\Desktop\cyrillic name\cyrillic name.csv' DELIMITER ',';
But it didn't work, also tried other encodings - it always returns the same result:
C:/Users/User/Desktop/some weird symbolic mess/some weird symbolic mess.csv: No such file or directory
It is for sure some weird issue with Windows encodings, is there a way to workaround this issue or the only way to solve this is to rename file path to full english?
CodePudding user response:
Sorry, but I don't think that there is a solution for your problem. The path in the COPY
statement is always in the database encoding, and if the operating system uses a different encoding, you are out of luck.
You could have created the database with the same encoding as the operating system, but anything other than UTF-8 is a bad choice. Perhaps you should switch to an operating system that has arrived in the 21st century and supports UTF-8.