pg_pinyin
PostgreSQL 拼音转写与检索辅助扩展
仓库
aiyou178/pg_pinyin
https://github.com/aiyou178/pg_pinyin
源码
pg_pinyin-0.0.2.tar.gz
pg_pinyin-0.0.2.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pg_pinyin | 0.0.2 | FTS | MIT | Rust |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 2190 | pg_pinyin | 否 | 是 | 否 | 是 | 否 | 是 | pinyin |
| 相关扩展 | 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
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.2 | 1817161514 | pg_pinyin | - |
| RPM | PIGSTY | 0.0.2 | 1817161514 | pg_pinyin_$v | - |
| DEB | PIGSTY | 0.0.2 | 1817161514 | postgresql-$v-pinyin | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.0.2 el8.x86_64.pg18 : pg_pinyin_18 pg_pinyin_18-0.0.2-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.0.2 el8.x86_64.pg17 : pg_pinyin_17 pg_pinyin_17-0.0.2-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.0.2 el8.x86_64.pg16 : pg_pinyin_16 pg_pinyin_16-0.0.2-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.0.2 el8.x86_64.pg15 : pg_pinyin_15 pg_pinyin_15-0.0.2-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.0.2 el8.x86_64.pg14 : pg_pinyin_14 pg_pinyin_14-0.0.2-1PIGSTY.el8.x86_64.rpm
|
| el8.aarch64 | PIGSTY 0.0.2 el8.aarch64.pg18 : pg_pinyin_18 pg_pinyin_18-0.0.2-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.0.2 el8.aarch64.pg17 : pg_pinyin_17 pg_pinyin_17-0.0.2-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.0.2 el8.aarch64.pg16 : pg_pinyin_16 pg_pinyin_16-0.0.2-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.0.2 el8.aarch64.pg15 : pg_pinyin_15 pg_pinyin_15-0.0.2-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.0.2 el8.aarch64.pg14 : pg_pinyin_14 pg_pinyin_14-0.0.2-1PIGSTY.el8.aarch64.rpm
|
| el9.x86_64 | PIGSTY 0.0.2 el9.x86_64.pg18 : pg_pinyin_18 pg_pinyin_18-0.0.2-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.0.2 el9.x86_64.pg17 : pg_pinyin_17 pg_pinyin_17-0.0.2-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.0.2 el9.x86_64.pg16 : pg_pinyin_16 pg_pinyin_16-0.0.2-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.0.2 el9.x86_64.pg15 : pg_pinyin_15 pg_pinyin_15-0.0.2-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.0.2 el9.x86_64.pg14 : pg_pinyin_14 pg_pinyin_14-0.0.2-1PIGSTY.el9.x86_64.rpm
|
| el9.aarch64 | PIGSTY 0.0.2 el9.aarch64.pg18 : pg_pinyin_18 pg_pinyin_18-0.0.2-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.0.2 el9.aarch64.pg17 : pg_pinyin_17 pg_pinyin_17-0.0.2-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.0.2 el9.aarch64.pg16 : pg_pinyin_16 pg_pinyin_16-0.0.2-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.0.2 el9.aarch64.pg15 : pg_pinyin_15 pg_pinyin_15-0.0.2-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.0.2 el9.aarch64.pg14 : pg_pinyin_14 pg_pinyin_14-0.0.2-1PIGSTY.el9.aarch64.rpm
|
| el10.x86_64 | PIGSTY 0.0.2 el10.x86_64.pg18 : pg_pinyin_18 pg_pinyin_18-0.0.2-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.0.2 el10.x86_64.pg17 : pg_pinyin_17 pg_pinyin_17-0.0.2-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.0.2 el10.x86_64.pg16 : pg_pinyin_16 pg_pinyin_16-0.0.2-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.0.2 el10.x86_64.pg15 : pg_pinyin_15 pg_pinyin_15-0.0.2-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.0.2 el10.x86_64.pg14 : pg_pinyin_14 pg_pinyin_14-0.0.2-1PIGSTY.el10.x86_64.rpm
|
| el10.aarch64 | PIGSTY 0.0.2 el10.aarch64.pg18 : pg_pinyin_18 pg_pinyin_18-0.0.2-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.0.2 el10.aarch64.pg17 : pg_pinyin_17 pg_pinyin_17-0.0.2-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.0.2 el10.aarch64.pg16 : pg_pinyin_16 pg_pinyin_16-0.0.2-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.0.2 el10.aarch64.pg15 : pg_pinyin_15 pg_pinyin_15-0.0.2-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.0.2 el10.aarch64.pg14 : pg_pinyin_14 pg_pinyin_14-0.0.2-1PIGSTY.el10.aarch64.rpm
|
| d12.x86_64 | PIGSTY 0.0.2 d12.x86_64.pg18 : postgresql-18-pinyin postgresql-18-pinyin_0.0.2-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.0.2 d12.x86_64.pg17 : postgresql-17-pinyin postgresql-17-pinyin_0.0.2-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.0.2 d12.x86_64.pg16 : postgresql-16-pinyin postgresql-16-pinyin_0.0.2-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.0.2 d12.x86_64.pg15 : postgresql-15-pinyin postgresql-15-pinyin_0.0.2-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.0.2 d12.x86_64.pg14 : postgresql-14-pinyin postgresql-14-pinyin_0.0.2-1PIGSTY~bookworm_amd64.deb
|
| d12.aarch64 | PIGSTY 0.0.2 d12.aarch64.pg18 : postgresql-18-pinyin postgresql-18-pinyin_0.0.2-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.0.2 d12.aarch64.pg17 : postgresql-17-pinyin postgresql-17-pinyin_0.0.2-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.0.2 d12.aarch64.pg16 : postgresql-16-pinyin postgresql-16-pinyin_0.0.2-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.0.2 d12.aarch64.pg15 : postgresql-15-pinyin postgresql-15-pinyin_0.0.2-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.0.2 d12.aarch64.pg14 : postgresql-14-pinyin postgresql-14-pinyin_0.0.2-1PIGSTY~bookworm_arm64.deb
|
| d13.x86_64 | PIGSTY 0.0.2 d13.x86_64.pg18 : postgresql-18-pinyin postgresql-18-pinyin_0.0.2-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.0.2 d13.x86_64.pg17 : postgresql-17-pinyin postgresql-17-pinyin_0.0.2-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.0.2 d13.x86_64.pg16 : postgresql-16-pinyin postgresql-16-pinyin_0.0.2-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.0.2 d13.x86_64.pg15 : postgresql-15-pinyin postgresql-15-pinyin_0.0.2-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.0.2 d13.x86_64.pg14 : postgresql-14-pinyin postgresql-14-pinyin_0.0.2-1PIGSTY~trixie_amd64.deb
|
| d13.aarch64 | PIGSTY 0.0.2 d13.aarch64.pg18 : postgresql-18-pinyin postgresql-18-pinyin_0.0.2-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.0.2 d13.aarch64.pg17 : postgresql-17-pinyin postgresql-17-pinyin_0.0.2-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.0.2 d13.aarch64.pg16 : postgresql-16-pinyin postgresql-16-pinyin_0.0.2-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.0.2 d13.aarch64.pg15 : postgresql-15-pinyin postgresql-15-pinyin_0.0.2-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.0.2 d13.aarch64.pg14 : postgresql-14-pinyin postgresql-14-pinyin_0.0.2-1PIGSTY~trixie_arm64.deb
|
| u22.x86_64 | PIGSTY 0.0.2 u22.x86_64.pg18 : postgresql-18-pinyin postgresql-18-pinyin_0.0.2-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.0.2 u22.x86_64.pg17 : postgresql-17-pinyin postgresql-17-pinyin_0.0.2-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.0.2 u22.x86_64.pg16 : postgresql-16-pinyin postgresql-16-pinyin_0.0.2-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.0.2 u22.x86_64.pg15 : postgresql-15-pinyin postgresql-15-pinyin_0.0.2-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.0.2 u22.x86_64.pg14 : postgresql-14-pinyin postgresql-14-pinyin_0.0.2-1PIGSTY~jammy_amd64.deb
|
| u22.aarch64 | PIGSTY 0.0.2 u22.aarch64.pg18 : postgresql-18-pinyin postgresql-18-pinyin_0.0.2-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.0.2 u22.aarch64.pg17 : postgresql-17-pinyin postgresql-17-pinyin_0.0.2-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.0.2 u22.aarch64.pg16 : postgresql-16-pinyin postgresql-16-pinyin_0.0.2-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.0.2 u22.aarch64.pg15 : postgresql-15-pinyin postgresql-15-pinyin_0.0.2-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.0.2 u22.aarch64.pg14 : postgresql-14-pinyin postgresql-14-pinyin_0.0.2-1PIGSTY~jammy_arm64.deb
|
| u24.x86_64 | PIGSTY 0.0.2 u24.x86_64.pg18 : postgresql-18-pinyin postgresql-18-pinyin_0.0.2-1PIGSTY~noble_amd64.deb
| PIGSTY 0.0.2 u24.x86_64.pg17 : postgresql-17-pinyin postgresql-17-pinyin_0.0.2-1PIGSTY~noble_amd64.deb
| PIGSTY 0.0.2 u24.x86_64.pg16 : postgresql-16-pinyin postgresql-16-pinyin_0.0.2-1PIGSTY~noble_amd64.deb
| PIGSTY 0.0.2 u24.x86_64.pg15 : postgresql-15-pinyin postgresql-15-pinyin_0.0.2-1PIGSTY~noble_amd64.deb
| PIGSTY 0.0.2 u24.x86_64.pg14 : postgresql-14-pinyin postgresql-14-pinyin_0.0.2-1PIGSTY~noble_amd64.deb
|
| u24.aarch64 | PIGSTY 0.0.2 u24.aarch64.pg18 : postgresql-18-pinyin postgresql-18-pinyin_0.0.2-1PIGSTY~noble_arm64.deb
| PIGSTY 0.0.2 u24.aarch64.pg17 : postgresql-17-pinyin postgresql-17-pinyin_0.0.2-1PIGSTY~noble_arm64.deb
| PIGSTY 0.0.2 u24.aarch64.pg16 : postgresql-16-pinyin postgresql-16-pinyin_0.0.2-1PIGSTY~noble_arm64.deb
| PIGSTY 0.0.2 u24.aarch64.pg15 : postgresql-15-pinyin postgresql-15-pinyin_0.0.2-1PIGSTY~noble_arm64.deb
| PIGSTY 0.0.2 u24.aarch64.pg14 : postgresql-14-pinyin postgresql-14-pinyin_0.0.2-1PIGSTY~noble_arm64.deb
|
| u26.x86_64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u26.aarch64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
构建
您可以使用 pig build 命令构建 pg_pinyin 扩展的 RPM / DEB 包:
pig build pkg pg_pinyin # 构建 RPM / DEB 包
安装
您可以直接安装 pg_pinyin 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install pg_pinyin; # 当前活跃 PG 版本安装
pig ext install -y pg_pinyin -v 18 # PG 18
pig ext install -y pg_pinyin -v 17 # PG 17
pig ext install -y pg_pinyin -v 16 # PG 16
pig ext install -y pg_pinyin -v 15 # PG 15
pig ext install -y pg_pinyin -v 14 # PG 14
dnf install -y pg_pinyin_18 # PG 18
dnf install -y pg_pinyin_17 # PG 17
dnf install -y pg_pinyin_16 # PG 16
dnf install -y pg_pinyin_15 # PG 15
dnf install -y pg_pinyin_14 # PG 14
apt install -y postgresql-18-pinyin # PG 18
apt install -y postgresql-17-pinyin # PG 17
apt install -y postgresql-16-pinyin # PG 16
apt install -y postgresql-15-pinyin # PG 15
apt install -y postgresql-14-pinyin # PG 14
创建扩展:
CREATE EXTENSION pg_pinyin;
用法
将中文字符转换为拼音罗马化,用于搜索和索引。可与 pg_trgm 配合实现模糊拼音搜索,或与 pg_search 配合实现基于词的搜索。
CREATE EXTENSION pg_pinyin;
函数
| 函数 | 说明 |
|---|---|
pinyin_char_romanize(text) | 字符级拼音罗马化 |
pinyin_char_romanize(text, suffix) | 使用自定义词典后缀 |
pinyin_word_romanize(text) | 词级拼音罗马化 |
pinyin_word_romanize(text, suffix) | 使用自定义词典后缀 |
生成列 + Trigram 搜索
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;
自定义词典
在 pinyin schema 中提供带后缀的自定义词典表:
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;
-- 使用自定义词典
SELECT public.pinyin_char_romanize('郑爽ABC', '_suffix1');