typeid
typeid
pg_typeid : Allows to use TypeIDs in Postgres natively
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4580 | typeid | pg_typeid | 0.3.0 | FUNC | MIT | Rust |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| See Also | pg_idkit pg_uuidv7 pgx_ulid uuid-ossp pg_hashids permuteseq |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.3.0 | 18 17 16 15 14 | pg_typeid | - |
| RPM | PIGSTY | 0.3.0 | 18 17 16 15 14 | pg_typeid_$v | - |
| DEB | PIGSTY | 0.3.0 | 18 17 16 15 14 | postgresql-$v-typeid | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
el8.aarch64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
el9.x86_64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
el9.aarch64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
el10.x86_64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
el10.aarch64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
d12.x86_64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
d12.aarch64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
d13.x86_64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
d13.aarch64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
u22.x86_64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
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 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
u24.aarch64 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 | PIGSTY 0.3.0 |
Source
pig build pkg pg_typeid; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_typeid; # install via package name, for the active PG version
pig install typeid; # install by extension name, for the current active PG version
pig install typeid -v 18; # install for PG 18
pig install typeid -v 17; # install for PG 17
pig install typeid -v 16; # install for PG 16
pig install typeid -v 15; # install for PG 15
pig install typeid -v 14; # install for PG 14Create this extension with:
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;Last updated on