Getting started with opencc
1. Install opencc
Install from Pigsty packages
CI tests PostgreSQL 14–18, and Pigsty ships packages for PostgreSQL 15–19 across Linux distributions (pg_opencc_18 on EL, postgresql-18-opencc on Debian/Ubuntu). Check Downloads for exact platform coverage.
Or build from source (PGXS)
Building from the release tag requires PostgreSQL server headers, CMake ≥ 3.12, a C++17 compiler, Python 3, and Make:
Clone the tagged release and install (pass with_llvm=no if your pg_config enables JIT without clang installed):
CMake builds static OpenCC and marisa libraries and compiles the dictionaries directly into the shared library.
2. Enable in a UTF8 database
opencc is a trusted extension—any role with CREATE privilege on the database can enable it without superuser rights. The SQL schema is fixed at opencc.
Calling text conversion in a non-UTF8 database raises opencc requires a UTF8 database.
3. Try your first conversions
Context-aware phrase conversion — Notice how
s2twptranslates the hardware term内存条while leaving the classical line海内存知己intact:Compare glyph-only vs. regional phrases — Every shorthand wrapper (such as
opencc.s2t,opencc.s2twp,opencc.tw2sp) is identical toopencc.convert(input, '<config>'):Target a locale with
opencc.localize()— Convert one Mainland source string into multiple regional variants in one query:List all built-in configs and routes:
Non-Chinese text, emoji, empty strings, and NULL pass through unchanged.
Next steps
- Guides and operations — Build cross-script search indexes, validate incoming text, proofread ambiguous conversions, preload dictionaries, and handle upgrades.
- SQL reference — Look up all 16 built-in configs, function signatures, and
opencc.preload.