# 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.

---

LLMS index: [llms.txt](/llms.txt)

---

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 {#configs}

| Config | Source → Target | Regional phrases | Maturity | Shorthand function |
| --- | --- | --- | --- | --- |
| `s2t` / `t2s` | `zh-Hans` ↔ `zh-Hant` | No | `stable` | `opencc.s2t()` / `opencc.t2s()` |
| `s2tw` / `tw2s` | `zh-Hans` ↔ `zh-TW` | No | `stable` | `opencc.s2tw()` / `opencc.tw2s()` |
| `s2twp` / `tw2sp` | `zh-Hans` ↔ `zh-TW` | Yes | `stable` | `opencc.s2twp()` / `opencc.tw2sp()` |
| `s2hk` / `hk2s` | `zh-Hans` ↔ `zh-HK` | No | `stable` | `opencc.s2hk()` / `opencc.hk2s()` |
| `s2hkp` / `hk2sp` | `zh-Hans` ↔ `zh-HK` | Yes | `developing` | `opencc.s2hkp()` / `opencc.hk2sp()` |
| `t2tw` / `tw2t` | `zh-Hant` ↔ `zh-TW` | No | `stable` | `opencc.t2tw()` / `opencc.tw2t()` |
| `t2hk` / `hk2t` | `zh-Hant` ↔ `zh-HK` | No | `stable` | `opencc.t2hk()` / `opencc.hk2t()` |
| `t2jp` / `jp2t` | `zh-Hant` ↔ `ja` | No | `experimental` | `opencc.t2jp()` / `opencc.jp2t()` |

## Conversion functions {#conversion}

| Name | Type | Default | Meaning |
| --- | --- | --- | --- |
| `opencc.convert(input text, config text)` | `text` | — | Convert text using one of the 16 built-in config names above. |
| `opencc.localize(input text, target text, source text)` | `text` | `source = '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` | — | 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>')`. |
{.fields meta="type default"}

## Script detection and inspection {#inspection}

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

## Views and operations {#catalog}

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

## Configuration (GUC) {#configuration}

| Name | Type | Default | Meaning |
| --- | --- | --- | --- |
| `opencc.preload` | string | `''` | 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. |
{.fields meta="type default"}

```sql
SELECT name, loaded FROM opencc.configs ORDER BY name;
```

---

Backlinks:

- [Getting started](/docs/opencc/getting-started/)
