Postgres 12 on Windows 7
This works:
CREATE DATABASE "foo"
ENCODING 'UTF8'
LC_COLLATE = 'en-US'
LC_CTYPE = 'en-US'
TEMPLATE template0
Afterwards, running SHOW LC_COLLATE
with database foo
selected reports:
But when running
SELECT UPPER('kedi' COLLATE "en-US")
it reports:
ERROR: collation "en-US" for encoding "UTF8" does not exist
Shouldn't both accept the same collation names?
Best Answer
LC_COLLATE
refers to a name of locale from the operating system, whereasCOLLATE
refers to a collation that should exist inpg_catalog.pg_collation
.pg_catalog.pg_collation
is originally populated in the template databases when the PostgreSQL instance is created (byinitdb
).Specifically it's the SQL function
pg_import_system_collations()
that should do that. From the doc (emphasis mine)For some reason you don't have
en-US
in pg_collation while it's valid from your operating system, so you seem to be in the case where the advice is to runpg_import_system_collations()
manually in the databases that need it.