Setting "ucs_basic" as the default database collation

Started by Christophe Pettusover 1 year ago4 messagesgeneral
Jump to latest
#1Christophe Pettus
xof@thebuild.com

Is there a way to specify "ucs_basic" (or the other "standard collations" [1]https://www.postgresql.org/docs/current/collation.html#COLLATION-MANAGING-STANDARD) collation as the default database collation at database creation time, rather than on a per-column or per-operation basis?

[1]: https://www.postgresql.org/docs/current/collation.html#COLLATION-MANAGING-STANDARD

#2Ron
ronljohnsonjr@gmail.com
In reply to: Christophe Pettus (#1)
Re: Setting "ucs_basic" as the default database collation

On Sun, Oct 27, 2024 at 5:32 AM Christophe Pettus <xof@thebuild.com> wrote:

Is there a way to specify "ucs_basic" (or the other "standard collations"
[1]) collation as the default database collation at database creation time,
rather than on a per-column or per-operation basis?

[1]
https://www.postgresql.org/docs/current/collation.html#COLLATION-MANAGING-STANDARD

https://www.postgresql.org/docs/16/sql-createdatabase.html

The CREATE DATABASE statement has an ENCODING option. Does that work with
'ucs_basic'?

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> crustacean!

#3Christophe Pettus
xof@thebuild.com
In reply to: Ron (#2)
Re: Setting "ucs_basic" as the default database collation

On Oct 27, 2024, at 13:56, Ron Johnson <ronljohnsonjr@gmail.com> wrote:

The CREATE DATABASE statement has an ENCODING option. Does that work with 'ucs_basic'?

No:

xof=# create database test encoding=ucs_basic;
ERROR: ucs_basic is not a valid encoding name
LINE 1: create database test encoding=ucs_basic;
^

Although that's not too surprising; it's a UTF-8 collation, not an encoding as such. Experimenting with the various other CREATE DATABASE parameters hasn't gotten me any farther.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Christophe Pettus (#1)
Re: Setting "ucs_basic" as the default database collation

Christophe Pettus <xof@thebuild.com> writes:

Is there a way to specify "ucs_basic" (or the other "standard collations" [1]) collation as the default database collation at database creation time, rather than on a per-column or per-operation basis?

CREATE DATABASE wants you to specify a locale, which ucs_basic is not.
It's defined by SQL as a standard collation name, but that doesn't
make it a complete locale specification. You can do something like

regression=# create database db1 with encoding = 'utf8' locale = 'en_US.utf8' template = template0;
CREATE DATABASE

or

regression=# create database db2 with encoding = 'utf8' icu_locale = 'en-US-x-icu' locale_provider = icu template = template0;
CREATE DATABASE

or

regression=# create database db3 with encoding = 'utf8' locale = 'POSIX' template = template0;
CREATE DATABASE

regards, tom lane