uri
URI Data type for PostgreSQL
Repository
petere/pguri
https://github.com/petere/pguri
Source
pguri-1.20251029.tar.gz
pguri-1.20251029.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_uri | 1.20251029 | TYPE | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 3840 | uri | No | Yes | No | Yes | No | Yes | - |
| Related | prefix semver unit pgpdf pglite_fusion md5hash asn1oid roaringbitmap |
|---|
+int flag
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.20251029 | 1817161514 | pg_uri | - |
| RPM | PIGSTY | 1.20251029 | 1817161514 | pg_uri_$v | - |
| DEB | PIGSTY | 1.20251029 | 1817161514 | postgresql-$v-pg-uri | - |
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
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
| Function | Returns | Description |
|---|---|---|
uri_scheme(uri) | text | Scheme (http, ftp, mailto) |
uri_userinfo(uri) | text | User info; NULL if absent |
uri_host(uri) | text | Hostname or IP address |
uri_host_inet(uri) | inet | IP host as inet; NULL if not IP |
uri_port(uri) | integer | Port number; NULL if unspecified |
uri_path(uri) | text | Path component (never NULL) |
uri_path_array(uri) | text[] | Path split by / |
uri_query(uri) | text | Query string; NULL if absent |
uri_fragment(uri) | text | Fragment; 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';
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.