CREATE_COLLATION(7)
๐ CREATE_COLLATION โ like, the manual page for PostgreSQL 18.6, bestie ๐
okay so welcome to the glow-up guide for CREATE COLLATION, straight out of the PostgreSQL 18.6 Documentation. grab a boba, we're defining collations today and it's gonna be iconic โจ
โจ NAME โจ
CREATE_COLLATION โ define a new collation ๐
๐ฆ SYNOPSIS ๐ฆ
CREATE COLLATION [ IF NOT EXISTS ] name (
[ LOCALE = locale, ]
[ LC_COLLATE = lc_collate, ]
[ LC_CTYPE = lc_ctype, ]
[ PROVIDER = provider, ]
[ DETERMINISTIC = boolean, ]
[ RULES = rules, ]
[ VERSION = version ]
)
CREATE COLLATION [ IF NOT EXISTS ] name FROM existing_collation
๐ธ DESCRIPTION ๐ธ
so CREATE COLLATION is literally how you make a brand new collation โ either by pulling the operating system locale settings, or by copying a collation that already exists. both are valid, both are cute ๐
and before you get any ideas: to create a collation, you must have CREATE privilege on the destination schema. no privilege, no collation, periodt.
๐ PARAMETERS ๐
IF NOT EXISTSโ bestie, this is the "no drama" flag. if a collation with the same name is already out there, don't throw an error, just send a notice instead. but heads up: there's no guarantee that the existing collation is anything like the one you were trying to make. it might be a whole different vibe. ๐nameโ the name of the collation, obviously ๐ it can be schema-qualified, and if it's not, the collation gets defined in the current schema. the name has to be unique within that schema. (fun fact: the system catalogs can hold collations with the same name for other encodings, but those get ignored if the database encoding doesn't match โ so don't stress about them.)localeโ the locale name for this collation. peep Section 23.2.2.3.1 and Section 23.2.2.3.2 for the details, they go deep.
if provider is libc, this is a shortcut for setting LC_COLLATE and LC_CTYPE at the same time โ two birds, one stone, slay. and if you specify locale, you cannot specify either of those two parameters. pick a lane, queen.
if provider is builtin, then locale must be specified, and it must be set to either C, C.UTF-8 or PG_UNICODE_FAST. those are the only options, no substitutions.
lc_collateโ ifproviderislibc, use the specified operating system locale for theLC_COLLATElocale category.lc_ctypeโ ifproviderislibc, use the specified operating system locale for theLC_CTYPElocale category.providerโ tells you which provider handles the locale services for this collation. possible values arebuiltin,icu(only if the server was built with ICU support) orlibc.libcis the default, it's the main character. see Section 23.1.4 for details.DETERMINISTICโ whether the collation uses deterministic comparisons. default istrue. a deterministic comparison treats strings that aren't byte-wise equal as unequal, even if the comparison considers them logically equal โ PostgreSQL breaks ties with a byte-wise comparison. a comparison that's not deterministic can make the collation, like, case-insensitive or accent-insensitive, which is kinda the whole point. for that you need to choose an appropriateLOCALEsetting and set the collation to not deterministic here.
nondeterministic collations are only supported with the ICU provider. that's the rule, no cap.
rulesโ extra collation rules to customize the behavior of the collation. ICU only, bestie. see Section 23.2.3.4 for details.versionโ the version string to store with the collation. normally you should justโฆ not. omitting it makes the version get computed from the actual version of the collation as provided by the operating system, which is usually what you want. this option exists forpg_upgradeto copy the version from an existing installation.
also see ALTER COLLATION (ALTER_COLLATION(7)) for how to deal with collation version mismatches ๐
existing_collationโ the name of an existing collation to copy. the new collation will have all the same properties as the existing one, but it's an independent object. it's giving twin energy, not clone energy ๐ซถ
๐ NOTES ๐
CREATE COLLATION takes a SHARE ROW EXCLUSIVE lock on the pg_collation system catalog, and that lock is self-conflicting โ so only one CREATE COLLATION command can run at a time. one at a time, we wait our turn, it's called manners ๐
use DROP COLLATION to remove user-defined collations.
see Section 23.2.2.3 for more info on how to create collations.
when you're using the libc collation provider, the locale must be applicable to the current database encoding. see CREATE DATABASE (CREATE_DATABASE(7)) for the precise rules โ they are precise, fr fr.
๐ฅ EXAMPLES ๐ฅ
making a collation from the operating system locale fr_FR.utf8 (assuming the current database encoding is UTF8):
CREATE COLLATION french (locale = 'fr_FR.utf8');
making a collation with the ICU provider, using German phone book sort order:
CREATE COLLATION german_phonebook (provider = icu, locale = 'de-u-co-phonebk');
making a collation with the ICU provider, based on the root ICU locale, with custom rules:
CREATE COLLATION custom (provider = icu, locale = 'und', rules = '&V << w <<< W');
see Section 23.2.3.4 for further details and examples on the rules syntax ๐
making a collation from an existing collation:
CREATE COLLATION german FROM "de_DE";
and this one is lowkey so convenient โ it lets you use operating-system-independent collation names in your applications. obsessed.
๐ COMPATIBILITY ๐
there is a CREATE COLLATION statement in the SQL standard, bestie, but it's limited to copying an existing collation only. the syntax for creating a brand new collation? that's a PostgreSQL extension. we invented that. ๐
โญ SEE ALSO โญ
ALTER COLLATION(ALTER_COLLATION(7))DROP COLLATION(DROP_COLLATION(7))
and that's the whole page, bestie! ๐ this was PostgreSQL 18.6, dated 2026, and it ATE. go forth and collate responsibly, mwah ๐โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms