Inserting Unicode Characters in Postgres

If you deal with foreign country/people names, you may have characters from different sets alongside each other. Putting these characters into a database can be challenging.

Below I will highlight how to do this for the Postgres Database. Assuming I have a “country” table with just one field for the name of the country, and I want to insert the country Côte d’Ivoire to the table:

postgres=# INSERT INTO country_table VALUES ('C' || U&'\00F4' || E'te d\'Ivoire');

Explanation:

  • The unicode character ‘ô’ is represented by U&’\00F4′
  • The character E preceding the last part of the country string is needed to tell Postgres to escape the \’ character within it.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s