uri

URI Data type for PostgreSQL

Overview

PackageVersionCategoryLicenseLanguage
pg_uri1.20251029TYPEPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
3840uriNoYesNoYesNoYes-
Relatedprefix semver unit pgpdf pglite_fusion md5hash asn1oid roaringbitmap

+int flag

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.202510291817161514pg_uri-
RPMPIGSTY1.202510291817161514pg_uri_$v-
DEBPIGSTY1.202510291817161514postgresql-$v-pg-uri-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

Build

You can build the RPM / DEB packages for pg_uri using pig build:

pig build pkg pg_uri         # build RPM / DEB packages

Install

You can install pg_uri directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install pg_uri;          # Install for current active PG version
pig ext install -y pg_uri -v 18  # PG 18
pig ext install -y pg_uri -v 17  # PG 17
pig ext install -y pg_uri -v 16  # PG 16
pig ext install -y pg_uri -v 15  # PG 15
pig ext install -y pg_uri -v 14  # PG 14
dnf install -y pg_uri_18       # PG 18
dnf install -y pg_uri_17       # PG 17
dnf install -y pg_uri_16       # PG 16
dnf install -y pg_uri_15       # PG 15
dnf install -y pg_uri_14       # PG 14
apt install -y postgresql-18-pg-uri   # PG 18
apt install -y postgresql-17-pg-uri   # PG 17
apt install -y postgresql-16-pg-uri   # PG 16
apt install -y postgresql-15-pg-uri   # PG 15
apt install -y postgresql-14-pg-uri   # PG 14

Create Extension:

CREATE EXTENSION uri;

Usage

uri: URI data type with validation and component extraction

The uri extension provides a data type for storing URIs with syntax validation per RFC 3986, component extraction functions, and human-friendly sorting.

CREATE EXTENSION uri;

CREATE TABLE links (
    id   int PRIMARY KEY,
    link uri
);

INSERT INTO links VALUES (1, 'https://github.com/petere/pguri');

Component Extraction Functions

FunctionReturnsDescription
uri_scheme(uri)textScheme (http, ftp, mailto)
uri_userinfo(uri)textUser info; NULL if absent
uri_host(uri)textHostname or IP address
uri_host_inet(uri)inetIP host as inet; NULL if not IP
uri_port(uri)integerPort number; NULL if unspecified
uri_path(uri)textPath component (never NULL)
uri_path_array(uri)text[]Path split by /
uri_query(uri)textQuery string; NULL if absent
uri_fragment(uri)textFragment; NULL if absent

Utility Functions

-- Normalize URI per RFC 3986
SELECT uri_normalize('HTTP://Example.COM/foo/../bar');

-- Percent-encode text
SELECT uri_escape('hello world', true, false);  -- hello+world

-- Decode percent-encoded text
SELECT uri_unescape('hello+world', true, false);  -- hello world

Example

SELECT uri_scheme(link), uri_host(link), uri_path(link)
FROM links
WHERE uri_host(link) = 'github.com';

Last Modified 2026-03-12: add pg extension catalog (95749bf)