Re: locale

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: locale
Date: 2004-04-07 17:28:45
Message-ID: 200404071728.i37HSjI13944@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dennis Bjorklund wrote:
> Is anyone working to make the locale support in pg better? Running initdb
> to set the locale is a bit heavy. It would be nice to at least be able to
> set it per database.

Oops, I confused locale and multibyte. Yes, I don't see a way to change
locale for new databases, but I don't see why we can't.

The initdb manual page says:

initdb initializes the database cluster's default locale
and character set encoding. Some locale categories are
fixed for the lifetime of the cluster, so it is important
to make the right choice when running initdb. Other
locale categories can be changed later when the server is
started. initdb will write those locale settings into the
postgresql.conf configuration file so they are the
default, but they can be changed by editing that file. To
set the locale that initdb uses, see the description of
the --locale option. The character set encoding can be set
separately for each database as it is created. initdb
determines the encoding for the template1 database, which
will serve as the default for all other databases. To
alter the default encoding use the --encoding option.

and

--locale=locale
Sets the default locale for the database cluster.
If this option is not specified, the locale is
inherited from the environment that initdb runs in.

--lc-collate=locale

--lc-ctype=locale

--lc-messages=locale

--lc-monetary=locale

--lc-numeric=locale

--lc-time=locale
Like --locale, but only sets the locale in the
specified category.

My only guess is that you can use ALTER DATABASE SET to set some of the
values when someone connects to the database.

Looking at guc.c I see:

{
{"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
gettext_noop("Shows the collation order locale."),
NULL,
GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
},
&locale_collate,
"C", NULL, NULL
},

{
{"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
gettext_noop("Shows the character classification and case conversion locale."),
NULL,
GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
},
&locale_ctype,
"C", NULL, NULL
},

{
{"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the language in which messages are displayed."),
NULL
},
&locale_messages,
"", locale_messages_assign, NULL
},

{
{"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting monetary amounts."),
NULL
},
&locale_monetary,
"C", locale_monetary_assign, NULL
},

{
{"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting numbers."),
NULL
},
&locale_numeric,
"C", locale_numeric_assign, NULL
},

{
{"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting date and time values."),
NULL
},
&locale_time,
"C", locale_time_assign, NULL
},

You can't change the internal ones, but you can modify some of the others.

Anyone know why we don't allow locale to be set per database?

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

  • locale at 2004-04-07 11:04:09 from Dennis Bjorklund

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2004-04-07 17:31:58 Re: locale
Previous Message Jan Wieck 2004-04-07 17:27:29 Re: Evening in NYC