prefix
prefix
pg_prefix : Prefix Range module for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3500 | prefix | pg_prefix | 1.2.10 | TYPE | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | semver ltree citext pg_trgm unit pgpdf pglite_fusion md5hash |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 1.2.10 | 18 17 16 15 14 | pg_prefix | - |
| RPM | PGDG | 1.2.10 | 18 17 16 15 14 | prefix_$v | - |
| DEB | PGDG | 1.2.10 | 18 17 16 15 14 | postgresql-$v-prefix | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
el8.aarch64 | PIGSTY 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
el9.x86_64 | PIGSTY 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
el9.aarch64 | PIGSTY 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
el10.x86_64 | PIGSTY 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
el10.aarch64 | PIGSTY 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
d12.x86_64 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
d12.aarch64 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
d13.x86_64 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
d13.aarch64 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
u22.x86_64 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
u22.aarch64 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
u24.x86_64 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
u24.aarch64 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 | PGDG 1.2.10 |
Source
pig build pkg pg_prefix; # build rpmInstall
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pg_prefix; # install via package name, for the active PG version
pig install prefix; # install by extension name, for the current active PG version
pig install prefix -v 18; # install for PG 18
pig install prefix -v 17; # install for PG 17
pig install prefix -v 16; # install for PG 16
pig install prefix -v 15; # install for PG 15
pig install prefix -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION prefix;Usage
The prefix extension provides a prefix_range data type for efficient prefix matching, particularly useful for telephony call routing.
Data Type
Create prefix_range values using the constructor or text casting:
CREATE EXTENSION prefix;
SELECT prefix_range('123'); -- 123
SELECT prefix_range('123', '4', '5'); -- 123[4-5]
SELECT '123'::prefix_range; -- 123Operators
| Operator | Description |
|---|---|
@> | Contains (prefix contains value) |
<@ | Is contained by |
&& | Overlaps |
| | Union |
& | Intersection |
=, <>, <, >, <=, >= | Comparison |
Examples
-- Find the longest matching prefix for a phone number
SELECT * FROM prefixes
WHERE prefix @> '0123456789'
ORDER BY length(prefix) DESC
LIMIT 1;
-- Containment check
SELECT '123'::prefix_range @> '123456'; -- true
-- Intersection
SELECT '123[4-5]' & '123[2-7]'; -- 123[4-5]
-- Union
SELECT '123' | '124'; -- 12[3-4]Index Support
Create a GiST index for efficient prefix lookups:
CREATE INDEX idx_prefix ON prefixes USING gist(prefix);The index accelerates @>, <@, &&, and = operators.
Last updated on