Skip to content

opencc SQL reference

Complete SQL API lookup for opencc v0.1.0 (vendored OpenCC 1.4.2): all 16 built-in configs, conversion and inspection functions, catalog views, and the opencc.preload GUC.

All functions and views live in the fixed opencc schema. Conversion, detection, and inspection functions are IMMUTABLE and PARALLEL SAFE within a release and require a UTF8 database.

Built-in configs

ConfigSource → TargetRegional phrasesMaturityShorthand function
s2t / t2szh-Hans ↔ zh-HantNostableopencc.s2t() / opencc.t2s()
s2tw / tw2szh-Hans ↔ zh-TWNostableopencc.s2tw() / opencc.tw2s()
s2twp / tw2spzh-Hans ↔ zh-TWYesstableopencc.s2twp() / opencc.tw2sp()
s2hk / hk2szh-Hans ↔ zh-HKNostableopencc.s2hk() / opencc.hk2s()
s2hkp / hk2spzh-Hans ↔ zh-HKYesdevelopingopencc.s2hkp() / opencc.hk2sp()
t2tw / tw2tzh-Hant ↔ zh-TWNostableopencc.t2tw() / opencc.tw2t()
t2hk / hk2tzh-Hant ↔ zh-HKNostableopencc.t2hk() / opencc.hk2t()
t2jp / jp2tzh-Hant ↔ jaNoexperimentalopencc.t2jp() / opencc.jp2t()

Conversion functions

opencc.convert(input text, config text) , text , default—
Convert text using one of the 16 built-in config names above.
opencc.localize(input text, target text, source text) , text , defaultsource = 'auto'
Route between zh-Hans, zh-Hant, zh-CN, zh-TW, zh-HK, and ja. Name source explicitly to translate regional phrases.
opencc.<config>(input text) , text , default—
Shorthand wrappers for all 16 configs (s2t, t2s, s2tw, tw2s, s2twp, tw2sp, s2hk, hk2s, s2hkp, hk2sp, t2tw, tw2t, t2hk, hk2t, t2jp, jp2t), equivalent to opencc.convert(input, '<config>').

Script detection and inspection

opencc.detect(input text) , text , default—
Heuristic script classification: none, neutral, simplified, traditional, mixed, or japanese.
opencc.script_stats(input text) , record , default—
Returns (han integer, simplified integer, traditional integer, kana integer).
opencc.explain(input text, config text) , table , default—
Returns (seq integer, source text, steps text[], output text) showing every conversion stage per segment.
opencc.ambiguities(input text, config text) , table , default—
Returns (pos integer, len integer, source text, output text, candidates text[]) for one-to-many dictionary spans.
opencc.candidates(word text, config text) , text[] , default—
Return every candidate output for word under config (default first; {} if absent).

Views and operations

opencc.configs , view , default—
Lists all 16 configs (name, source, target, phrases, maturity, description, loaded). loaded reflects the current backend.
opencc.routes , view , default—
Lists all 36 localize() region pairs (source, target, chain, maturity).
opencc.version() , record , default—
STABLE. Returns (extension text, opencc text, dictionary text) including the SHA-256 digest of embedded dictionaries.
opencc.dependents() , table , default—
STABLE. Returns (kind text, object text, uses text, action text) for stored catalog dependents and their rebuild SQL.

Configuration (GUC)

opencc.preload , string , default''
Comma-separated config names (or 'all') to initialize when the library loads. Combine with shared_preload_libraries = 'opencc' and restart PostgreSQL to share read-only dictionary pages across backends.
SELECT name, loaded FROM opencc.configs ORDER BY name;