pg_strverscmp
pg_strverscmp · Natural-sort comparison functions, text operators, and a btree operator class based on a strverscmp-like order.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100290 | pg_strverscmp | pg_strverscmp | 1.0 | FUNC | ISC | C |
Usage
Sources:
pg_strverscmp 1.0 provides a natural, version-like ordering for text, so numeric runs compare by value rather than purely character by character. It exposes pg_strverscmp(text,text), six comparison operators, and the strverscmp_ops B-tree operator class.
Natural ordering
The operators are +<, +<=, +=, +<>, +>=, and +>. To support indexed searches with the same semantics, declare a text index with strverscmp_ops; ordinary text indexes use PostgreSQL’s normal collation and operator class instead.
Important limitations
The build links against libunistring. Upstream describes the comparator as Unicode-aware and generally case-insensitive, but explicitly warns that it is not binary-safe around a NUL byte, does not use PostgreSQL collation facilities, and is inefficient because it repeatedly invokes Unicode collation while comparing characters. Treat this as a specialized ordering, not a drop-in replacement for locale-aware text equality. Keep query operators and index operator classes consistent, and verify ordering after library or platform changes.