Monday, December 12, 2005

Forcing postgreSQL 8.0 default encoding

If anyone knows a better way to set the default encoding please let me know it.
I also tried the -E option to specify SQL_ASCII encoding when running initdb, but it gave me error messages, complaining about compatibility with my locale (ISO8859-1).

So I logged in as root, switched to postgres user, then launched psql console connected to template1 database.

# su - postgres
$ psql template1
Welcome to psql 8.0.3, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit


then I performed the following command to see which encoding is set for the template database:

template1=# select datname, encoding from pg_database;
datname | encoding
-----------+----------
template1 | 6
template0 | 6
(2 rows)


I discovered that 6 stands for UNICODE. Don't tell me why, cause I don't know, the encoding attribute is shown here as an integer but everywhere its type is a varchar.

So, let's set it as SQL_ASCII (integer 0):

template1=# update pg_database set encoding = 0;
UPDATE 2
template1=# select datname, encoding from pg_database;
datname | encoding
-----------+----------
template1 | 0
template0 | 0
(2 rows)


Then I created a new database:

template1=# create database pippo;
CREATE DATABASE
template1=# select datname, encoding from pg_database;
datname | encoding
-----------+----------
template1 | 0
template0 | 0
pippo | 0
(3 rows)


Hoorray! I got it. Party time now.

0 Comments:

Post a Comment

<< Home