Skip to content

PostgreSQL 8.4'de Türkçe sıralama destekli veritabanı yaratmak

PostgreSQL'de mevcut sürümlerde Türkçe sıralama desteği için initdb aşamasında encoding'i Türkçe vermek gerekiyordu. 8.4 ile gelen yeni bir özellikle buna gerek kalmadı. Anlatayım:

Aşağıda 8.4 psql'inden \l ile alınmış bir çıktı parçası var:

postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
regression | postgres | SQL_ASCII | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | {=c/postgres,postgres=CTc/postgres}
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | {postgres=CTc/postgres,=c/postgres}


Bu sunucuda initdb'yi en_US.UTF-8 ile yapmıştık. Şimdi yeni özelliği deneyelim:


[postgres@[local]:pagila]=# CREATE DATABASE collationtest ENCODING 'UTF-8' COLLATE 'tr_TR.UTF-8';
ERROR: new collation is incompatible with the collation of the template database (en_US.UTF-8)
HINT: Use the same collation as in the template database, or use template0 as template


Yani veritabanını yaratırken template1'in dil kodlaması kullanılır. PostgreSQL'de yeni veritabanı yaratılırken şablon olarak öntanımlı olarak template1 veritabanı kullanılır. İpucu mesajında da söylendiği gibi şablon olarak template0 kullanalım:


[postgres@[local]:pagila]=# CREATE DATABASE collationtest ENCODING 'UTF-8' COLLATE 'tr_TR.UTF-8' TEMPLATE template0;
CREATE DATABASE


Güzel. Şimdi \l çıktısının ilgili kısmına bakalım:


Name | Owner | Encoding | Collation | Ctype | Access Privileges
------------------------+-----------+-----------+-------------+-------------+---------------------------------------------------------
collationtest | postgres | UTF8 | tr_TR.UTF-8 | en_US.UTF-8 |


Gördüğünüz gibi Collation artık Türkçe. Şimdi basit bir test ile sıralamanın doğru olduğunu kendiniz de onaylayabilirsiniz.

Artık ayrıca bir initdb yapmaya gerek yok :-)

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

peacemaker on :

merhaba,
Postgresql 8.3'te latin5 tipinde veritabanı oluşturabiliyordum. Ancak 8.4'te bunu yapamıyorum. Bir yöntemi var mıdır. forumlarda konu ile ilgili pek birşey bulamadım. teşekkürler

peacemaker on :

ayrıca
initdb -D [veriklasoru] ile bakınca

Öntanımlı veritabanı dil kodlaması WIN1254 olarak ayarlandı.

görünüyor, ancak PGADIMIII ile yeni veri tabanı oluşturmaya çalışıp, bunun encodingini WIN1254 seçmeye çalıştığımda - ki encodingi UTF8 görünüyor, hata veriyor, bundan dolayıdırki WIN1254 veya LATIN5 seçilemiyor.

Devrim GÜNDÜZ on :

UTF-8 yok mu Windows'da?

Koray on :

\l çıktım aşağıdaki gibi Ben sizin örneğinizdeki gibi template0 kullanarak database oluşturmak istemim ERROR başlığı altındaki hatayı aldım

List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres

ERROR
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres

Can Erogul on :

Postgres 9.1.3'te COLLATE yerine LC_COLLATE demek gerekiyormuş.

postgres=# CREATE DATABASE collationtest ENCODING='UTF-8' LC_COLLATE='tr_TR.UTF-8' TEMPLATE=template0;
ERROR: invalid locale name tr_TR.UTF-8
Sadece tr_TR ya da UTF-8 yazmak da yetmedi. en_US.UTF-8 yazarsam yapıyor ama.

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Form options