Skip to content
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.5
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

optional tokenizer-input overload can integrate with pg_search.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.0.5
18
17
16
15
14
pg_pinyin -
RPM
PIGSTY
0.0.5
18
17
16
15
14
pg_pinyin_$v -
DEB
PIGSTY
0.0.5
18
17
16
15
14
postgresql-$v-pinyin -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
el8.aarch64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
el9.x86_64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
el9.aarch64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
el10.x86_64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
el10.aarch64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
d12.x86_64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
d12.aarch64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
d13.x86_64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
d13.aarch64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
u22.x86_64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
u22.aarch64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
u24.x86_64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
u24.aarch64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
u26.x86_64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
u26.aarch64
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
PIGSTY 0.0.5
Package Version OS ORG SIZE File URL
pg_pinyin_18 0.0.5 el8.x86_64 pigsty 3.0 MiB pg_pinyin_18-0.0.5-1PIGSTY.el8.x86_64.rpm
pg_pinyin_18 0.0.5 el8.aarch64 pigsty 2.8 MiB pg_pinyin_18-0.0.5-1PIGSTY.el8.aarch64.rpm
pg_pinyin_18 0.0.5 el9.x86_64 pigsty 2.9 MiB pg_pinyin_18-0.0.5-1PIGSTY.el9.x86_64.rpm
pg_pinyin_18 0.0.5 el9.aarch64 pigsty 2.8 MiB pg_pinyin_18-0.0.5-1PIGSTY.el9.aarch64.rpm
pg_pinyin_18 0.0.5 el10.x86_64 pigsty 2.9 MiB pg_pinyin_18-0.0.5-1PIGSTY.el10.x86_64.rpm
pg_pinyin_18 0.0.5 el10.aarch64 pigsty 2.8 MiB pg_pinyin_18-0.0.5-1PIGSTY.el10.aarch64.rpm
postgresql-18-pinyin 0.0.5 d12.x86_64 pigsty 2.5 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~bookworm_amd64.deb
postgresql-18-pinyin 0.0.5 d12.aarch64 pigsty 2.2 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~bookworm_arm64.deb
postgresql-18-pinyin 0.0.5 d13.x86_64 pigsty 2.5 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~trixie_amd64.deb
postgresql-18-pinyin 0.0.5 d13.aarch64 pigsty 2.2 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~trixie_arm64.deb
postgresql-18-pinyin 0.0.5 u22.x86_64 pigsty 2.7 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~jammy_amd64.deb
postgresql-18-pinyin 0.0.5 u22.aarch64 pigsty 2.6 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~jammy_arm64.deb
postgresql-18-pinyin 0.0.5 u24.x86_64 pigsty 2.7 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~noble_amd64.deb
postgresql-18-pinyin 0.0.5 u24.aarch64 pigsty 2.6 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~noble_arm64.deb
postgresql-18-pinyin 0.0.5 u26.x86_64 pigsty 2.7 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~resolute_amd64.deb
postgresql-18-pinyin 0.0.5 u26.aarch64 pigsty 2.6 MiB postgresql-18-pinyin_0.0.5-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_pinyin;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install 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 14

Create this extension with:

CREATE EXTENSION pg_pinyin;

Usage

Sources:

pg_pinyin romanizes Chinese text and exposes tokenizer and query helpers for search applications. Use pg_pinyin to create stable Pinyin search keys, tokenize Han text, or expand Pinyin input into a pg_search regular-expression query.

Version 0.0.5 is primarily a packaging and toolchain update; its upgrade script makes no SQL catalog changes, so the user-facing API remains compatible with 0.0.4.

Create the Extension

CREATE EXTENSION pg_pinyin;

The extension is relocatable and does not require shared_preload_libraries or a server restart.

Romanize Text

Romanize character by character or use word-aware segmentation:

SELECT pinyin_char_romanize('重庆');
SELECT pinyin_word_romanize('重庆火锅');
SELECT pinyin_word_romanize('重庆火锅', ' ');

Both functions accept an optional suffix inserted after each emitted Pinyin unit. Character mode is deterministic per character; word mode uses the bundled word dictionary to resolve contextual pronunciations.

Use pg_search Tokenizer Input

Word romanization also accepts a pg_search tokenizer result when that extension is available:

SELECT pinyin_word_romanize(
  description::pdb.icu::text[]
)
FROM documents;

The overload returns romanized text; it does not expose a row-per-token API. Use the plain-text overload when pg_search tokenization is not required.

Build a pg_search Query

When pg_search was installed before pg_pinyin, pg_pinyin provides a typed overload that returns pdb.query:

SELECT *
FROM documents
WHERE id @@@ pinyin_regex_phrase(
  'chong qing',
  slope => 1,
  max_expansions => 64,
  generated_pinyin => true
);

If pg_search is absent, the same entry point is installed as an error-reporting stub rather than silently returning a different type. Install dependencies in the intended order and test the function signature after upgrades.

Object Index

  • pinyin_char_romanize(text [, suffix]) returns character-based Pinyin text.
  • pinyin_word_romanize(text [, suffix]) returns dictionary-segmented Pinyin text.
  • pinyin_word_romanize(tokenizer_input [, suffix]) accepts a pg_search tokenizer result.
  • pinyin_regex_phrase(text, slope, max_expansions, generated_pinyin) constructs a pg_search Pinyin phrase query when that integration is available.
  • pinyin_regex_phrase_patterns is an internal pattern-building helper; prefer the public query function.

Operational Notes

The extension ships generated character and word dictionaries in its pinyin schema. Treat those tables as extension-managed data rather than application tables. Romanization is normalization, not translation, and ambiguous or domain-specific readings may require application-side review.

Last updated on