typeid

Allows to use TypeIDs in Postgres natively

Overview

PackageVersionCategoryLicenseLanguage
pg_typeid0.3.0FUNCMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
4580typeidNoYesNoYesNoNo-
Relatedpg_idkit pg_uuidv7 pgx_ulid uuid-ossp pg_hashids permuteseq

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.3.01817161514pg_typeid-
RPMPIGSTY0.3.01817161514pg_typeid_$v-
DEBPIGSTY0.3.01817161514postgresql-$v-typeid-
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
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u24.x86_64
u24.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0

Build

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

pig build pkg pg_typeid         # build RPM / DEB packages

Install

You can install pg_typeid 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_typeid;          # Install for current active PG version
pig ext install -y pg_typeid -v 18  # PG 18
pig ext install -y pg_typeid -v 17  # PG 17
pig ext install -y pg_typeid -v 16  # PG 16
pig ext install -y pg_typeid -v 15  # PG 15
pig ext install -y pg_typeid -v 14  # PG 14
dnf install -y pg_typeid_18       # PG 18
dnf install -y pg_typeid_17       # PG 17
dnf install -y pg_typeid_16       # PG 16
dnf install -y pg_typeid_15       # PG 15
dnf install -y pg_typeid_14       # PG 14
apt install -y postgresql-18-typeid   # PG 18
apt install -y postgresql-17-typeid   # PG 17
apt install -y postgresql-16-typeid   # PG 16
apt install -y postgresql-15-typeid   # PG 15
apt install -y postgresql-14-typeid   # PG 14

Create Extension:

CREATE EXTENSION typeid;

Usage

typeid: TypeID support for PostgreSQL - type-safe, sortable UUIDs with a prefix

TypeID is an extension of UUIDv7 with a type prefix, stored internally as a prefix + binary UUID.

CREATE EXTENSION typeid;

Functions

FunctionReturn TypeDescription
typeid_generate(prefix TEXT)typeidGenerate a new TypeID with the given prefix
typeid_generate_nil()typeidGenerate a TypeID with an empty prefix
typeid_is_valid(input TEXT)BOOLEANCheck if a TypeID string is valid
typeid_prefix(typeid)TEXTExtract the prefix from a TypeID
typeid_to_uuid(typeid)UUIDConvert a TypeID to a UUID
uuid_to_typeid(prefix TEXT, uuid UUID)typeidConvert a UUID to a TypeID
typeid_uuid_generate_v7()UUIDGenerate a UUID v7
typeid_has_prefix(typeid, prefix TEXT)BOOLEANCheck if a TypeID has a specific prefix
typeid_is_nil_prefix(typeid)BOOLEANCheck if a TypeID has a nil prefix
typeid_generate_batch(prefix TEXT, count INTEGER)SETOF typeidGenerate a batch of TypeIDs

Operators

  • <, <=, =, >=, >, <> for comparing TypeIDs
  • @> for checking if a TypeID has a certain prefix (e.g. id @> 'user')
  • B-tree operator class for indexing

Examples

-- Create table with TypeID primary key
CREATE TABLE users (
  id typeid DEFAULT typeid_generate('user') NOT NULL PRIMARY KEY,
  created_at timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
);

-- Insert data
INSERT INTO users (id) SELECT typeid_generate('user') FROM generate_series(1, 100);

-- Extract prefix
SELECT typeid_prefix(id) FROM users LIMIT 1;  -- 'user'

-- Check prefix with operator
SELECT * FROM users WHERE id @> 'user';

-- Convert to UUID
SELECT typeid_to_uuid(id) FROM users LIMIT 1;

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