typeid
Allows to use TypeIDs in Postgres natively
Repository
blitss/typeid-postgres
https://github.com/blitss/typeid-postgres
Source
typeid-postgres-0.3.0.tar.gz
typeid-postgres-0.3.0.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_typeid | 0.3.0 | FUNC | MIT | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4580 | typeid | No | Yes | No | Yes | No | No | - |
| Related | pg_idkit pg_uuidv7 pgx_ulid uuid-ossp pg_hashids permuteseq |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.3.0 | 1817161514 | pg_typeid | - |
| RPM | PIGSTY | 0.3.0 | 1817161514 | pg_typeid_$v | - |
| DEB | PIGSTY | 0.3.0 | 1817161514 | postgresql-$v-typeid | - |
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
| Function | Return Type | Description |
|---|---|---|
typeid_generate(prefix TEXT) | typeid | Generate a new TypeID with the given prefix |
typeid_generate_nil() | typeid | Generate a TypeID with an empty prefix |
typeid_is_valid(input TEXT) | BOOLEAN | Check if a TypeID string is valid |
typeid_prefix(typeid) | TEXT | Extract the prefix from a TypeID |
typeid_to_uuid(typeid) | UUID | Convert a TypeID to a UUID |
uuid_to_typeid(prefix TEXT, uuid UUID) | typeid | Convert a UUID to a TypeID |
typeid_uuid_generate_v7() | UUID | Generate a UUID v7 |
typeid_has_prefix(typeid, prefix TEXT) | BOOLEAN | Check if a TypeID has a specific prefix |
typeid_is_nil_prefix(typeid) | BOOLEAN | Check if a TypeID has a nil prefix |
typeid_generate_batch(prefix TEXT, count INTEGER) | SETOF typeid | Generate 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;
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.