I have recently started using PostgreSQL for creating/updating existing SQL databases. Being rather new in this I came across an issue of selecting correct encoding type while creating new database. UTF-8 (default) did not work for me as data to be included is of various languages (English, Chinese, Japanese, Russia etc) as well as includes symbolic characters.
Question: What is the right database encoding type to satisfy my needs.
Any help is highly appreciated.
-
4Actually UTF-8 is your only option to accept characters from all languages.Daniel Vérité– Daniel Vérité2013年11月10日 13:12:53 +00:00Commented Nov 10, 2013 at 13:12
-
Thanks Daniel, thanks for your prompt response. That is strange than a i have been trying to import .csv file and and the error i am getting refers to unknown character for UTF8 format. Might be related to the fact that i'm creating .csv file on office for macuser2959843– user29598432013年11月10日 15:31:37 +00:00Commented Nov 10, 2013 at 15:31
-
Yes, presumably it's invalid UTF-8. Check out Filtering invalid utf8. The usual answer is the one based on iconv.Daniel Vérité– Daniel Vérité2013年11月10日 21:26:28 +00:00Commented Nov 10, 2013 at 21:26
1 Answer 1
There are four different encoding settings at play here:
The server side encoding for the database
The
client_encodingthat the PostgreSQL client announces to the PostgreSQL server. The PostgreSQL server assumes that text coming from the client is inclient_encodingand converts it to the server encoding.The operating system default encoding. This is the default
client_encodingset bypsqlif you don't provide a different one. Other client drivers might have different defaults; eg PgJDBC always usesutf-8.The encoding of any files or text being sent via the client driver. This is usually the OS default encoding, but it might be a different one - for example, your OS might be set to use
utf-8by default, but you might be trying toCOPYsome CSV content that was saved aslatin-1.
You almost always want the server encoding set to utf-8. It's the rest that you need to change depending on what's appropriate for your situation. You would have to give more detail (exact error messages, file contents, etc) to be able to get help with the details.