1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! `pg_ts_config` + `pg_ts_config_map` catalog queries.
//!
//! Two queries are registered:
//!
//! 1. [`SELECT_TS_CONFIGURATIONS`] — one row per text-search configuration in
//! the managed schemas, with the parser schema+name resolved via a join to
//! `pg_ts_parser` and its namespace.
//!
//! 2. [`SELECT_TS_CONFIG_MAPPINGS`] — one row per (config, `token_type`, dict)
//! triple, ordered by `(config_schema, config_name, token_alias, mapseqno)`.
//! `ts_token_type(cfgparser)` is called via a `LATERAL` to resolve the
//! integer `maptokentype` to its human-readable alias (e.g. `word`,
//! `asciiword`). Dictionaries within a token type are in ascending
//! `mapseqno` order so the assembler can rely on row order for the
//! fallback chain.
//!
//! Extension-owned configurations (`pg_depend.deptype = 'e'`) are excluded at
//! the SQL layer. Both queries take `$1::text[]` (managed-schema names).
/// Fetch one row per user-defined text-search configuration in the managed
/// schemas.
///
/// Columns returned:
/// - `schema_name` — configuration schema (`pg_namespace.nspname`)
/// - `name` — configuration name (`pg_ts_config.cfgname`)
/// - `parser_schema` — parser schema (`pg_namespace.nspname` for parser)
/// - `parser_name` — parser name (`pg_ts_parser.prsname`)
/// - `owner` — role name from `pg_get_userbyid(cfgowner)`
/// - `comment` — from `pg_description` (NULL when absent)
///
/// Extension-owned configurations are excluded via a `NOT EXISTS` subquery on
/// `pg_depend`. Takes `$1::text[]` (managed-schema names).
pub const SELECT_TS_CONFIGURATIONS: &str = "\
SELECT \
n.nspname::text AS schema_name, \
c.cfgname::text AS name, \
pn.nspname::text AS parser_schema, \
p.prsname::text AS parser_name, \
pg_catalog.pg_get_userbyid(c.cfgowner)::text AS owner, \
de.description::text AS comment \
FROM pg_catalog.pg_ts_config c \
JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace \
JOIN pg_catalog.pg_ts_parser p ON p.oid = c.cfgparser \
JOIN pg_catalog.pg_namespace pn ON pn.oid = p.prsnamespace \
LEFT JOIN pg_catalog.pg_description de \
ON de.objoid = c.oid \
AND de.classoid = 'pg_catalog.pg_ts_config'::regclass \
AND de.objsubid = 0 \
WHERE n.nspname = ANY($1::text[]) \
AND NOT EXISTS ( \
SELECT 1 \
FROM pg_catalog.pg_depend dep \
WHERE dep.classid = 'pg_catalog.pg_ts_config'::regclass \
AND dep.objid = c.oid \
AND dep.deptype = 'e' \
) \
ORDER BY n.nspname, c.cfgname";
/// Fetch one row per (config, `token_type`, dictionary) triple in the managed
/// schemas, ordered so that dictionaries within each (config, `token_type`) are
/// in ascending `mapseqno` order.
///
/// Columns returned:
/// - `config_schema` — config's schema name
/// - `config_name` — config name
/// - `token_type` — token alias (e.g. `word`, `asciiword`) from `ts_token_type`
/// - `dict_schema` — dictionary schema
/// - `dict_name` — dictionary name
/// - `mapseqno` — sequence number within the mapping (1-based, ascending)
///
/// The `LATERAL ts_token_type(c.cfgparser)` call resolves the integer
/// `maptokentype` to its canonical alias string. Extension-owned configs are
/// excluded by mirroring the same `NOT EXISTS` filter used in
/// [`SELECT_TS_CONFIGURATIONS`]. Takes `$1::text[]` (managed-schema names).
pub const SELECT_TS_CONFIG_MAPPINGS: &str = "\
SELECT \
n.nspname::text AS config_schema, \
c.cfgname::text AS config_name, \
tt.alias::text AS token_type, \
dn.nspname::text AS dict_schema, \
d.dictname::text AS dict_name, \
m.mapseqno::bigint AS mapseqno \
FROM pg_catalog.pg_ts_config_map m \
JOIN pg_catalog.pg_ts_config c ON c.oid = m.mapcfg \
JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace \
JOIN pg_catalog.pg_ts_dict d ON d.oid = m.mapdict \
JOIN pg_catalog.pg_namespace dn ON dn.oid = d.dictnamespace \
JOIN LATERAL ts_token_type(c.cfgparser) tt ON tt.tokid = m.maptokentype \
WHERE n.nspname = ANY($1::text[]) \
AND NOT EXISTS ( \
SELECT 1 \
FROM pg_catalog.pg_depend dep \
WHERE dep.classid = 'pg_catalog.pg_ts_config'::regclass \
AND dep.objid = c.oid \
AND dep.deptype = 'e' \
) \
ORDER BY n.nspname, c.cfgname, tt.alias, m.mapseqno";