Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C69691337BA3 for ; Sat, 7 May 2011 09:02:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 83370-10 for ; Sat, 7 May 2011 12:02:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sd-17937.dedibox.fr (sd-17937.dedibox.fr [88.191.100.74]) by mail.postgresql.org (Postfix) with ESMTP id 98D981337B97 for ; Sat, 7 May 2011 09:02:41 -0300 (ADT) Received: from [192.168.10.3] (ASte-Genev-Bois-153-1-47-183.w83-200.abo.wanadoo.fr [83.200.29.183]) by sd-17937.dedibox.fr (Postfix) with ESMTPA id 835AB3B8F5; Sat, 7 May 2011 14:02:41 +0200 (CEST) Message-ID: <4DC534E1.40801@lelarge.info> Date: Sat, 07 May 2011 14:02:41 +0200 From: Guillaume Lelarge User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 MIME-Version: 1.0 To: Thomas Kellerer CC: pgsql-sql@postgresql.org Subject: Re: Specifying column level collations References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/41 X-Sequence-Number: 35325 On 05/07/2011 01:19 PM, Thomas Kellerer wrote: > Hi, > > I'm playing around with 9.1beta1 and would like to create a table where > one column has a non-default collation. > > But whatever I try, I can't find the correct name that I have to use. > > My database is initialized as follows: > > postgres=# select version(); > version > ---------------------------------------------------------------- > PostgreSQL 9.1beta1, compiled by Visual C++ build 1500, 32-bit > (1 row) > > postgres=# select name, setting > postgres-# from pg_settings > postgres-# where name in ('lc_collate', 'server_encoding', > 'client_encoding'); > name | setting > -----------------+--------------------- > client_encoding | WIN1252 > lc_collate | German_Germany.1252 > server_encoding | UTF8 > (3 rows) > > > Now I'm trying to create a table where one column's collation is set to > french: > > create table foo (bar text collate "fr_FR") --> collation "fr_FR" for > encoding "UTF8" does not exist > create table foo (bar text collate "fr_FR.1252") --> collation "fr_FR" > for encoding "UTF8" does not exist > create table foo (bar text collate "fr_FR.UTF8") --> collation "fr_FR" > for encoding "UTF8" does not exist > create table foo (bar text collate "French_France.1252") --> collation > "French_France.1252" for encoding "UTF8" does not exist > > So, how do I specify the collation there? > You first need to use "CREATE COLLATION", such as: b1=# CREATE COLLATION fr (locale='fr_FR'); CREATE COLLATION Then, you'll be able to create your table: b1=# CREATE TABLE foo (bar TEXT COLLATE fr); CREATE TABLE b1=# \d foo Table "public.foo" Column | Type | Modifiers --------+------+------------ bar | text | collate fr > And is there a command to show me all available collations that I can use? > b1=# select * from pg_collation; collname | collnamespace | collowner | collencoding | collcollate | collctype ------------+---------------+-----------+--------------+-------------+------------ default | 11 | 10 | -1 | | C | 11 | 10 | -1 | C | C POSIX | 11 | 10 | -1 | POSIX | POSIX en_AG | 11 | 10 | 6 | en_AG | en_AG en_AG.utf8 | 11 | 10 | 6 | en_AG.utf8 | [...] fr_FR | 11 | 10 | 6 | fr_FR.utf8 | fr_FR.utf8 fr_FR.utf8 | 11 | 10 | 6 | fr_FR.utf8 | fr_FR.utf8 fr_LU | 11 | 10 | 6 | fr_LU.utf8 | fr_LU.utf8 fr_LU.utf8 | 11 | 10 | 6 | fr_LU.utf8 | fr_LU.utf8 ucs_basic | 11 | 10 | 6 | C | C fr | 2200 | 10 | 6 | fr_FR.UTF8 | fr_FR.UTF8 (47 rows) Or \dO (o in uppercase) inside psql: b1=# \dO List of collations Schema | Name | Collate | Ctype --------+------+------------+------------ public | fr | fr_FR.UTF8 | fr_FR.UTF8 (1 row) -- Guillaume http://www.postgresql.fr http://dalibo.com