CREATE_COLLATION(7pg15)
π NAME π
Okay bestie, welcome to the CREATE_COLLATION(7pg15) page β this is the whole vibe for CREATE COLLATION, the command that defines a new collation. Periodt. π
β¨ 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 π¦
So CREATE COLLATION defines a new collation using the specified operating system locale settings, or by copying an existing collation. Easy concept, iconic execution. π
To be able to create a collation, you must have CREATE privilege on the destination schema. No privilege, no collation, no cap. π
π 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. One setting, two jobs β sheβs efficient. π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. 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 the ICU provider. Thatβs the rule, bestie. β¨
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 also ALTER 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. Sheβs copying the fit, not the identity. π
π₯ NOTES π₯
CREATE COLLATIONtakes aSHARE ROW EXCLUSIVElock, which is self-conflicting, on thepg_collationsystem catalog, so only oneCREATE COLLATIONcommand can run at a time. Not me waiting in line π but okay.- 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. Slay. β¨
π« 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. Iconic of PostgreSQL, honestly. π
π«Ά SEE ALSO π«Ά
ALTER COLLATION (ALTER_COLLATION(7))DROP COLLATION (DROP_COLLATION(7))
Thatβs the whole page, bestie π β source/version is PostgreSQL 15.19, dated 2026, and the footer manual name is CREATE COLLATION(7). Go forth and collate responsibly. π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-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