uuid-ossp
uuid-ossp
uuid-ossp : generate universally unique identifiers (UUIDs)
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4930 | uuid-ossp
|
uuid-ossp
|
1.1 |
FUNC
|
PostgreSQL
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-dt-
|
No
|
Yes
|
No
|
Yes
|
no
|
yes
|
| Relationships | |
|---|---|
| Need By | babelfishpg_tsql
|
| See Also | pg_idkit
pgx_ulid
pg_uuidv7
pg_hashids
sequential_uuids
permuteseq
ddsketch
vasco
|
Packages
| PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|
1.1
|
1.1
|
1.1
|
1.1
|
1.1
|
This is a built-in contrib extension ship with the PostgreSQL kernel
Install
Create this extension with:
CREATE EXTENSION uuid-ossp;Usage
Provides functions to generate UUIDs using several standard algorithms. Note: for simple random UUIDs, consider using the built-in gen_random_uuid() instead.
CREATE EXTENSION "uuid-ossp";UUID Generation Functions
| Function | Description |
|---|---|
uuid_generate_v1() |
Version 1: MAC address + timestamp |
uuid_generate_v1mc() |
Version 1 with random multicast MAC |
uuid_generate_v3(namespace uuid, name text) |
Version 3: MD5 hash of namespace + name |
uuid_generate_v4() |
Version 4: fully random |
uuid_generate_v5(namespace uuid, name text) |
Version 5: SHA-1 hash of namespace + name (preferred over v3) |
Namespace Constants
| Function | Description |
|---|---|
uuid_nil() |
Nil UUID (all zeros) |
uuid_ns_dns() |
DNS namespace |
uuid_ns_url() |
URL namespace |
uuid_ns_oid() |
ISO OID namespace |
uuid_ns_x500() |
X.500 DN namespace |
Examples
-- Random UUID (v4)
SELECT uuid_generate_v4();
-- Timestamp-based UUID (v1)
SELECT uuid_generate_v1();
-- Deterministic UUID from name (v5, preferred over v3)
SELECT uuid_generate_v5(uuid_ns_url(), 'http://www.postgresql.org');
-- Use as default primary key
CREATE TABLE items (
id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,
name text
);Last updated on