A function translating a collation name to an OID

to_regcollation() is a system function for translating the name of a collation to its OID.

to_regcollation() was added in PostgreSQL 13.


to_regcollation ( text ) → regcollation

to_regcollation() is equivalent to using the regcollation object identifier type cast, but returns NULL rather than raising an ERROR if no matching collation is found.

The current search path is considered when evaluating the provided collation name.

The collation name is case-sensitive and will need to be quoted if it contains upper-case characters.

Change history


Basic usage example for to_regcollation():

postgres=# SELECT to_regcollation('pg_catalog."C"')::oid;
(1 row)

NULL is returned if the specified collation does not exist or is not found:

postgres=# SELECT to_regcollation('foo')::oid IS NULL;
(1 row)

If the specified collation is not visible in the current search path, it must be schema-qualified:

postgres=# SELECT to_regcollation('british_english'), to_regcollation('collations.british_english');
 to_regcollation |      to_regcollation       
                 | collations.british_english
(1 row)


Collation, System function

See also

regcollation, pg_collation_is_visible()