Batuhan Aydın
Batuhan Aydın

Reputation: 53

Printing different language characters in psql

I want to store multiple languages at the same column. First i'm creating db and tables.

CREATE DATABASE dbname ENCODING 'UTF8'

I'm saving the data succesfully, but when i want to print it with a SELECT query, i get this error using psql.

ERROR:  character with byte sequence 0xd9 0x84 in encoding "UTF8" has no equivalent in encoding "WIN1254"

So WIN1254 is Turkish which have different characters like ç, ş, ü... But i don't get this error only when i exclude Arabic, so the problem is not Turkish but Arabic. How can i solve this? Maybe i should do something while creating the db. Also while i'm printing, it doesn't print Turkish characters succesfully, just putting wrong characters.

Upvotes: 1

Views: 1053

Answers (2)

Timur Shtatland
Timur Shtatland

Reputation: 12347

In the psql session, set the client encoding to match server encoding:

SET client_encoding TO 'UTF8';

Find server_encoding like so:

SHOW server_encoding;

For example:

psql <whatever>
=> SELECT * FROM table_foo;
ERROR:  character with byte sequence 0xef 0xbf 0xbd in encoding "UTF8" has no equivalent in encoding "LATIN9"
=> SHOW server_encoding;
 server_encoding 
-----------------
 UTF8
(1 row)
=> SET client_encoding TO 'UTF8';
SET
=> select * from table_foo;
-- Now OK

SEE ALSO:

PostgreSQL: Documentation: 23.3. Character Set Support: https://www.postgresql.org/docs/current/multibyte.html

Upvotes: 2

Laurenz Albe
Laurenz Albe

Reputation: 246248

If your application or your client should display characters from different languages, they have to use a client encoding in which these characters are defined.

Arabic characters are not defined in WIN1254, so you have to use a different encoding. Typically, one would use UTF-8 or one of the UTF-16 encodings for that. Since PostgreSQL does not support UTF-16, UTF-8 is the way to go.

Since you are using Windows, matters may be more complicated, since there is no support for UTF-8 on the command line.

Upvotes: 1

Related Questions