Skip to main content

uqa_sql/catalog/
collations.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Built-in collation identities shared by declarations and OID alias input/output.
8
9/// Predefined `PostgreSQL` 18 collation names and OIDs.
10const BUILTIN_COLLATIONS: [(&str, i64); 7] = [
11    ("default", 100),
12    ("pg_c_utf8", 811),
13    ("C", 950),
14    ("POSIX", 951),
15    ("ucs_basic", 962),
16    ("unicode", 963),
17    ("pg_unicode_fast", 6411),
18];
19
20/// The `pg_collation` OID of a built-in collation name.
21#[must_use]
22pub fn builtin_collation_oid(name: &str) -> Option<i64> {
23    BUILTIN_COLLATIONS
24        .iter()
25        .find(|(collation, _)| *collation == name)
26        .map(|(_, oid)| *oid)
27}
28
29/// The name of a built-in collation selected by its catalog OID.
30#[must_use]
31pub fn builtin_collation_name(oid: i64) -> Option<&'static str> {
32    BUILTIN_COLLATIONS
33        .iter()
34        .find_map(|(name, candidate)| (*candidate == oid).then_some(*name))
35}