CREATE_COLLATION(7pg16)

πŸ“¦ version 16.15, in opensuse-leap 16.0

πŸ’… CREATE_COLLATION β€” the glow-up πŸ’…

okay so bestie, this is the CREATE COLLATION page from PostgreSQL 16.15 (2026 date, we're serving). it's literally all about defining a new collation, and I'm gonna walk you through every single flag because we don't gatekeep here. periodt. ✨

✨ NAME ✨

CREATE_COLLATION β€” define a new collation. that's it. that's the vibe. πŸ’–

πŸ¦‹ SYNOPSIS πŸ¦‹

two ways to slay, bestie:

CREATE COLLATION [ IF NOT EXISTS ] name (
    [ LOCALE = locale, ]
    [ LC_COLLATE = lc_collate, ]
    [ LC_CTYPE = lc_ctype, ]
    [ PROVIDER = provider, ]
    [ DETERMINISTIC = boolean, ]
    [ RULES = rules, ]
    [ VERSION = version ]
)

or the copy-paste remix:

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. lowkey iconic.

to be able to create a collation, you must have CREATE privilege on the destination schema. no privilege, no collation, sorry bestie. πŸ™ˆ

πŸŽ€ PARAMETERS πŸŽ€

every parameter, no cap:

  • 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. so like, proceed with caution but also it's fine. πŸ’…
  • 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.) so yeah, name it something cute and unique. ✨
  • locale β€” the locale name for this collation. see Section 24.2.2.3.1 and Section 24.2.2.3.2 for details. if provider is libc, this is a shortcut for setting LC_COLLATE and LC_CTYPE at once. if you specify locale, you cannot specify either of those parameters. it's giving convenience but with rules. 🫢
  • lc_collate β€” if provider is libc, use the specified operating system locale for the LC_COLLATE locale category. that's the collation part, bestie. πŸ”₯
  • lc_ctype β€” if provider is libc, use the specified operating system locale for the LC_CTYPE locale category. that's the character type part. πŸ’œ
  • provider β€” specifies the provider to use for locale services associated with this collation. possible values are icu (if the server was built with ICU support) or libc. libc is the default. see Section 24.1.4 for details. choose your fighter. πŸ‘‘
  • DETERMINISTIC β€” specifies whether the collation should use deterministic comparisons. the default is true. 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 appropriate LOCALE setting and set the collation to not deterministic here. nondeterministic collations are only supported with the ICU provider. so like, if you want case-insensitive vibes, you need ICU and to set this to false. no libc shenanigans. 😭
  • rules β€” specifies additional collation rules to customize the behavior of the collation. this is supported for ICU only. see Section 24.2.3.4 for details. custom rules are so main character. 🌈
  • 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 by pg_upgrade for copying the version from an existing installation. see also ALTER COLLATION (ALTER_COLLATION(7)) for how to handle collation version mismatches. so like, don't touch unless you're pg_upgrade. fr fr. πŸ’€
  • 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. so you get a clone, not a reference. slay. 🧚

πŸ’€ 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. so like, no parallel collation creation, bestie. one at a time. 🚦
  • use DROP COLLATION to remove user-defined collations. don't just leave them lying around. πŸ—‘οΈ
  • see Section 24.2.2.3 for more information on how to create collations. iykyk. πŸ“–
  • 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. so like, don't try to use a locale that doesn't match your encoding, it won't end well. πŸ™…β€β™€οΈ

πŸ“ EXAMPLES πŸ“

okay so here are the looks, bestie:

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 24.2.3.4 for further details and examples on the rules syntax. the rules syntax is a whole vibe, go read it. πŸ“š

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. so like, you can name it something cute and not worry about the OS naming. πŸ’–

🌈 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. so like, we're special. periodt. πŸ‘‘

πŸ”₯ SEE ALSO πŸ”₯


okay bestie, that's the whole page. sourced from PostgreSQL 16.15 docs, dated 2026, and it's literally the CREATE COLLATION(7) page. now go define some collations and slay. mwah. πŸ’‹βœ¨

πŸ“¦ where this page comes from