CREATE_COLLATION(7pg17)
π NAME π
CREATE COLLATION(7) β aka CREATE_COLLATION β is literally define a new collation, bestie. This is the CREATE COLLATION manual page, and we're gonna make collations, copy collations, and keep every single receipt. π
β¨ SYNOPSIS β¨
Okay so there are two iconic forms, no cap:
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 π¦
CREATE COLLATION defines a new collation using the specified operating system locale settings, or by copying an existing collation. Slay.
To be able to create a collation, you must have CREATE privilege on the destination schema. That's the vibe check, bestie. π
πΈ 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.) iykyk β¨localeβ The locale name for this collation. See Section 23.2.2.3.1 and Section 23.2.2.3.2 for details. Ifproviderislibc, this is a shortcut for settingLC_COLLATEandLC_CTYPEat once. If you specifylocale, you cannot specify either of those parameters. Ifproviderisbuiltin, thenlocalemust be specified and set to eitherCorC.UTF-8. π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β Specifies the provider to use for locale services associated with this collation. Possible values arebuiltin,icu(if the server was built with ICU support) orlibc.libcis the default. See Section 23.1.4 for details. π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. π«Ά
Warning bestie: Nondeterministic collations are only supported with the ICU provider. No exceptions. π
rulesβ Specifies additional collation rules to customize the behavior of the collation. This is supported for ICU only. See Section 23.2.3.4 for details. π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. Main character energy, but make it a whole new object. β¨
π₯ NOTES π₯
CREATE COLLATION takes a SHARE ROW EXCLUSIVE lock, which is self-conflicting, on the pg_collation system catalog, so only one CREATE COLLATION command can run at a time. Fr fr, it's a one-at-a-time situation. βοΈ
Use DROP COLLATION to remove user-defined collations. π§Ή
See Section 23.2.2.3 for more information on how to create collations.
When 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. Do not skip that part, bestie. π«Ά
π 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 using 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. π¦
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. Iconic, honestly. π
β 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. Periodt. π
π SEE ALSO π
ALTER COLLATION(ALTER_COLLATION(7))DROP COLLATION(DROP_COLLATION(7))
π cute little sign-off: this glow-up came from the PostgreSQL 17.11 documentation, dated 2026, and the page is CREATE COLLATION(7). Mwah, bestie. π«Άπβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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