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
9pub mod declarations;
10pub(crate) mod derivation;
11pub mod expression;
12
13/// The database-default collation's predefined `PostgreSQL` catalog identity.
14pub const DEFAULT_COLLATION_OID: i64 = 100;
15
16/// Predefined `PostgreSQL` 18 collation names and OIDs.
17const BUILTIN_COLLATIONS: [(&str, i64); 7] = [
18    ("default", DEFAULT_COLLATION_OID),
19    ("pg_c_utf8", 811),
20    ("C", 950),
21    ("POSIX", 951),
22    ("ucs_basic", 962),
23    ("unicode", 963),
24    ("pg_unicode_fast", 6411),
25];
26
27/// The `pg_collation` OID of a built-in collation name.
28#[must_use]
29pub fn builtin_collation_oid(name: &str) -> Option<i64> {
30    BUILTIN_COLLATIONS
31        .iter()
32        .find(|(collation, _)| *collation == name)
33        .map(|(_, oid)| *oid)
34}
35
36/// The name of a built-in collation selected by its catalog OID.
37#[must_use]
38pub fn builtin_collation_name(oid: i64) -> Option<&'static str> {
39    BUILTIN_COLLATIONS
40        .iter()
41        .find_map(|(name, candidate)| (*candidate == oid).then_some(*name))
42}