prefix

pg_prefix : Prefix Range module for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3500
prefix
pg_prefix
1.2.10
TYPE
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
semver
ltree
citext
pg_trgm
unit
pgpdf
pglite_fusion
md5hash

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
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 / PGPG18PG17PG16PG15PG14
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
PackageVersionOSORGSIZEFile URL
prefix_151.2.10el8.x86_64pgdg30.0 KiBprefix_15-1.2.10-1PGDG.rhel8.x86_64.rpm
prefix_151.2.9el8.x86_64pgdg51.8 KiBprefix_15-1.2.9-3.rhel8.x86_64.rpm
prefix_151.2.10el8.aarch64pgdg28.2 KiBprefix_15-1.2.10-1PGDG.rhel8.aarch64.rpm
prefix_151.2.9el8.aarch64pgdg49.9 KiBprefix_15-1.2.9-3.rhel8.aarch64.rpm
prefix_151.2.10el9.x86_64pgdg27.4 KiBprefix_15-1.2.10-1PGDG.rhel9.x86_64.rpm
prefix_151.2.9el9.x86_64pgdg50.5 KiBprefix_15-1.2.9-3.rhel9.x86_64.rpm
prefix_151.2.10el9.aarch64pgdg26.4 KiBprefix_15-1.2.10-1PGDG.rhel9.aarch64.rpm
prefix_151.2.9el9.aarch64pgdg49.3 KiBprefix_15-1.2.9-3.rhel9.aarch64.rpm
prefix_151.2.10el10.x86_64pgdg28.3 KiBprefix_15-1.2.10-3PGDG.rhel10.x86_64.rpm
prefix_151.2.10el10.aarch64pgdg27.4 KiBprefix_15-1.2.10-3PGDG.rhel10.aarch64.rpm
postgresql-15-prefix1.2.10d12.x86_64pgdg40.3 KiBpostgresql-15-prefix_1.2.10-4.pgdg12+1_amd64.deb
postgresql-15-prefix1.2.10d12.aarch64pgdg39.2 KiBpostgresql-15-prefix_1.2.10-4.pgdg12+1_arm64.deb
postgresql-15-prefix1.2.10d13.x86_64pgdg40.3 KiBpostgresql-15-prefix_1.2.10-4.pgdg13+1_amd64.deb
postgresql-15-prefix1.2.10d13.aarch64pgdg39.4 KiBpostgresql-15-prefix_1.2.10-4.pgdg13+1_arm64.deb
postgresql-15-prefix1.2.10u22.x86_64pgdg44.0 KiBpostgresql-15-prefix_1.2.10-4.pgdg22.04+1_amd64.deb
postgresql-15-prefix1.2.10u22.aarch64pgdg42.9 KiBpostgresql-15-prefix_1.2.10-4.pgdg22.04+1_arm64.deb
postgresql-15-prefix1.2.10u24.x86_64pgdg40.2 KiBpostgresql-15-prefix_1.2.10-4.pgdg24.04+1_amd64.deb
postgresql-15-prefix1.2.10u24.aarch64pgdg39.3 KiBpostgresql-15-prefix_1.2.10-4.pgdg24.04+1_arm64.deb

Source

pig build pkg pg_prefix;		# build rpm

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

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

Create this extension with:

CREATE EXTENSION prefix;

Usage

prefix: prefix range type for phone number routing

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;           -- 123

Operators

OperatorDescription
@>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