CREATE_COLLATION(7pg14)
β¨ NAME β¨
okay so bestie, this is the CREATE_COLLATION page β the CREATE_COLLATION(7pg14) one from PostgreSQL 14.24 β and itβs literally all about defining a new collation π
β¨. In one-line manpage terms: define a new collation. Thatβs the whole vibe. π
β¨ SYNOPSIS β¨
CREATE COLLATION [ IF NOT EXISTS ] name (
[ LOCALE = locale, ]
[ LC_COLLATE = lc_collate, ]
[ LC_CTYPE = lc_ctype, ]
[ PROVIDER = provider, ]
[ DETERMINISTIC = boolean, ]
[ VERSION = version ]
)
CREATE COLLATION [ IF NOT EXISTS ] name FROM existing_collation
β¨ DESCRIPTION β¨
okay so what does CREATE COLLATION do? It defines a new collation using the specified operating system locale settings, or by copying an existing collation π¦. Thatβs the main character move.
To be able to create a collation, you must have CREATE privilege on the destination schema. No privilege, no collation, periodt π.
β¨ PARAMETERS β¨
IF NOT EXISTSβ do not throw an error if a collation with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing collation is anything like the one that would have been created π.nameβ the name of the collation. The collation name can be schema-qualified. If it is not, the collation is defined in the current schema. The collation name must be unique within that schema. (The system catalogs can contain collations with the same name for other encodings, but these are ignored if the database encoding does not match.) πlocaleβ this is a shortcut for settingLC_COLLATEandLC_CTYPEat once. If you specify this, you cannot specify either of those parameters β οΈ.lc_collateβ use the specified operating system locale for theLC_COLLATElocale category πΈ.lc_ctypeβ use the specified operating system locale for theLC_CTYPElocale category πΈ.providerβ specifies the provider to use for locale services associated with this collation. Possible values are:icu,libc.libcis the default. The available choices depend on the operating system and build options π§.DETERMINISTICβ specifies whether the collation should use deterministic comparisons. The default istrue. A deterministic comparison considers strings that are not byte-wise equal to be unequal even if they are considered logically equal by the comparison. PostgreSQL breaks ties using a byte-wise comparison. A comparison that is not deterministic can make the collation be, say, case- or accent-insensitive. For that, you need to choose an appropriateLOCALEsetting and set the collation to not deterministic here. Nondeterministic collations are only supported with theICUprovider π¨.versionβ specifies the version string to store with the collation. Normally, this should be omitted, which will cause the version to be computed from the actual version of the collation as provided by the operating system. This option is intended to be used bypg_upgradefor copying the version from an existing installation. See alsoALTER COLLATION(ALTER_COLLATION(7)) for how to handle collation version mismatches π«Ά.existing_collationβ the name of an existing collation to copy. The new collation will have the same properties as the existing one, but it will be an independent object π.
β¨ NOTES β¨
CREATE COLLATIONtakes aSHARE ROW EXCLUSIVElock, which is self-conflicting, on thepg_collationsystem catalog, so only oneCREATE COLLATIONcommand can run at a time π.- Use
DROP COLLATIONto remove user-defined collations π§Ή. - See Section 24.2.2.3 for more information on how to create collations π.
- When using the
libccollation provider, the locale must be applicable to the current database encoding. SeeCREATE DATABASE(CREATE_DATABASE(7)) for the precise rules π§.
β¨ EXAMPLES β¨
To create a collation from the operating system locale fr_FR.utf8 (assuming the current database encoding is UTF8):
CREATE COLLATION french (locale = 'fr_FR.utf8');
To create a collation using the ICU provider using German phone book sort order:
CREATE COLLATION german_phonebook (provider = icu, locale = 'de-u-co-phonebk');
To create a collation from an existing collation:
CREATE COLLATION german FROM "de_DE";
This can be convenient to be able to use operating-system-independent collation names in applications β¨.
β¨ COMPATIBILITY β¨
There is a CREATE COLLATION statement in the SQL standard, but it is limited to copying an existing collation. The syntax to create a new collation is a PostgreSQL extension π
.
β¨ SEE ALSO β¨
ALTER COLLATION(ALTER_COLLATION(7))DROP COLLATION(DROP_COLLATION(7))
okay thatβs the whole page bestie π«Ά β source/version: PostgreSQL 14.24, dated 2026. Slay responsibly, and remember: collations are literally the vibe check for your strings πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms