Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF8 Postgresql Create Database Like MySQL (including character set, encoding, and lc_type)

For the following MySQL create database statement, what would be the equivalent in postgresql?:

CREATE DATABASE IF NOT EXISTS `scratch`    DEFAULT CHARACTER SET = utf8   DEFAULT COLLATE = utf8_unicode_ci; 

I currently have:

CREATE DATABASE "scratch"   WITH OWNER "postgres"   ENCODING 'UTF8'   TABLESPACE "pg_default"; 

Is that enough or should I be more specific including LOCALE as well?

like image 698
Wil Moore III Avatar asked Apr 01 '12 04:04

Wil Moore III


People also ask

How do I set mysql database to UTF-8?

To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name: Copy ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci; To exit the mysql program, type \q at the mysql> prompt.

Does PostgreSQL support UTF-8?

The character set support in PostgreSQL allows you to store text in a variety of character sets (also called encodings), including single-byte character sets such as the ISO 8859 series and multiple-byte character sets such as EUC (Extended Unix Code), UTF-8, and Mule internal code.

Does mysql use UTF-8?

MySQL supports multiple Unicode character sets: utf8mb4 : A UTF-8 encoding of the Unicode character set using one to four bytes per character.


1 Answers

Yes, you can be more specific.

For example:

CREATE DATABASE "scratch"   WITH OWNER "postgres"   ENCODING 'UTF8'   LC_COLLATE = 'en_US.UTF-8'   LC_CTYPE = 'en_US.UTF-8'; 

Also I recommend to read the following pages about locales and collations in PostgreSQL:

  • http://www.postgresql.org/docs/current/interactive/locale.html
  • http://www.postgresql.org/docs/current/interactive/collation.html
like image 150
michael.bochkaryov Avatar answered Oct 08 '22 12:10

michael.bochkaryov