Chinese pinyin conversion, polyphonic phrase disambiguation, and ordered pinyin matching
Compatibility Matrix
This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.
| Platform | 1.4.4 | 1.4.5 | 1.5.5 | 1.5.6 | 2.0.0 |
|---|---|---|---|---|---|
| Linux AMD64 | |||||
| Linux ARM64 | |||||
| macOS AMD64 | |||||
| macOS ARM64 | |||||
| Windows AMD64 | |||||
| Windows ARM64 | |||||
| WebAssembly |
Installing and Loading
INSTALL duck_pinyin FROM community;
LOAD duck_pinyin;
Example
LOAD duck_pinyin;
SELECT pinyin_char_romanize('我ABC们123');
SELECT pinyin_word_romanize('重庆银行');
SELECT pinyin_matches('wu han huang he lou', 'whh');
About duck_pinyin
Native Chinese pinyin conversion and ordered phrase matching, ported from pg_pinyin with pinned embedded dictionaries. Includes character conversion, longest-phrase polyphonic disambiguation, batch documents, pre-tokenized input, and explicit per-call dictionary overrides.
Query modes include full syllables, initials, autocomplete, automatic, and legacy compatibility parsing. Ordered matching supports a total skipped-token budget. The core extension is independent of PostgreSQL and FTS.
An optional official FTS/BM25 SQL example is provided separately. Its current dynamic-term macro has a documented correlated-query scaling limitation; consult the repository benchmarks before using that example on large tables.
Extension code is MIT licensed. Embedded phrase dictionary data includes CC-BY-SA-4.0 material. Source attribution, pinned data manifests, and complete data license texts are included in the repository and release archives. Qualified with DuckDB 2.0.0 using the legacy V1 C API entrypoint.
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| pinyin_char_romanize | scalar | NULL | NULL | |
| pinyin_matches | scalar | NULL | NULL | |
| pinyin_phrase | scalar | NULL | NULL | |
| pinyin_regex_phrase | scalar | NULL | NULL | |
| pinyin_regex_phrase_mode | scalar | NULL | NULL | |
| pinyin_regex_phrase_patterns | scalar | NULL | NULL | |
| pinyin_regex_phrase_patterns_mode | scalar | NULL | NULL | |
| pinyin_word_romanize | scalar | NULL | NULL | |
| pinyin_word_romanize_batch | scalar | NULL | NULL | |
| pinyin_word_romanize_tokens | scalar | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
| name | description | input_type | scope | aliases | typed_value |
|---|---|---|---|---|---|
| temp_directory | Set the directory to which temporary files are written. | VARCHAR | GLOBAL | [] | post.db.tmp |