pg_pinyin
pg_pinyin
pg_pinyin : Pinyin romanization and search helpers for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2190 | pg_pinyin
|
pg_pinyin
|
0.0.2 |
FTS
|
MIT
|
Rust
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r
|
No
|
Yes
|
No
|
Yes
|
yes
|
no
|
| Relationships | |
|---|---|
| Schemas | pinyin |
| See Also | zhparser
pg_search
pg_trgm
pg_bigm
pgroonga
pgroonga_database
pg_tokenizer
fuzzystrmatch
|
pgrx 0.17.0; optional tokenizer-input overload can integrate with pg_search
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
0.0.2 |
18
17
16
15
14
|
pg_pinyin |
- |
| RPM | PIGSTY
|
0.0.2 |
18
17
16
15
14
|
pg_pinyin_$v |
- |
| DEB | PIGSTY
|
0.0.2 |
18
17
16
15
14
|
postgresql-$v-pinyin |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
el8.aarch64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
el9.x86_64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
el9.aarch64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
el10.x86_64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
el10.aarch64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
d12.x86_64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
d12.aarch64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
d13.x86_64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
d13.aarch64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
u22.x86_64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
u22.aarch64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
u24.x86_64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
u24.aarch64
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
PIGSTY 0.0.2
|
Source
pig build pkg pg_pinyin; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_pinyin; # install via package name, for the active PG version
pig install pg_pinyin -v 18; # install for PG 18
pig install pg_pinyin -v 17; # install for PG 17
pig install pg_pinyin -v 16; # install for PG 16
pig install pg_pinyin -v 15; # install for PG 15
pig install pg_pinyin -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pg_pinyin;Usage
pg_pinyin: Pinyin romanization and search helpers for PostgreSQL
Convert Chinese characters to Pinyin romanization for search and indexing. Works well with pg_trgm for fuzzy Pinyin search or pg_search for word-based search.
CREATE EXTENSION pg_pinyin;Functions
| Function | Description |
|---|---|
pinyin_char_romanize(text) |
Character-level Pinyin romanization |
pinyin_char_romanize(text, suffix) |
With custom dictionary suffix |
pinyin_word_romanize(text) |
Word-level Pinyin romanization |
pinyin_word_romanize(text, suffix) |
With custom dictionary suffix |
Generated Column + Trigram Search
CREATE EXTENSION IF NOT EXISTS pg_pinyin;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE TABLE voice (
id bigserial PRIMARY KEY,
description text NOT NULL,
pinyin text GENERATED ALWAYS AS (public.pinyin_char_romanize(description)) STORED
);
CREATE INDEX voice_pinyin_trgm_idx ON voice USING gin (pinyin gin_trgm_ops);
INSERT INTO voice (description) VALUES ('郑爽ABC');
SELECT id, description, pinyin FROM voice;Custom Dictionary
Provide custom dictionary tables in schema pinyin with a suffix:
CREATE TABLE IF NOT EXISTS pinyin.pinyin_mapping_suffix1 (
character text PRIMARY KEY,
pinyin text NOT NULL
);
CREATE TABLE IF NOT EXISTS pinyin.pinyin_words_suffix1 (
word text PRIMARY KEY,
pinyin text NOT NULL
);
INSERT INTO pinyin.pinyin_mapping_suffix1 (character, pinyin)
VALUES ('郑', '|zhengx|')
ON CONFLICT (character) DO UPDATE SET pinyin = EXCLUDED.pinyin;
-- Use custom dictionary
SELECT public.pinyin_char_romanize('郑爽ABC', '_suffix1');Last updated on