UUID
UUID stores a universally unique identifier. Text input is parsed as a UUID and displayed using its canonical lowercase, hyphenated spelling.
Syntax
text
UUIDInvalid UUID text raises TYPE_MISMATCH. UUID values support equality, ordering, grouping and indexes. They are identifiers rather than numeric operands; direct numeric arithmetic and numeric aggregates reject them.
Use gen_random_uuid() for a random version 4 UUID or uuidv7() for a time-ordered version 7 UUID. These functions produce native UUID values.
Usage Example
Normalizing UUID text
sql
SELECT CAST('550E8400-E29B-41D4-A716-446655440000' AS UUID)
FORMAT csv;text
"550e8400-e29b-41d4-a716-446655440000"Using a UUID key
sql
CREATE TABLE documents(id UUID PRIMARY KEY, title String);
INSERT INTO documents VALUES
('550e8400-e29b-41d4-a716-446655440000', 'Project notes');sql
SELECT title
FROM documents
WHERE id = '550e8400-e29b-41d4-a716-446655440000'
FORMAT csv;text
"Project notes"Checking a generated UUID version
sql
SELECT uuid_extract_version(gen_random_uuid()),
uuid_extract_version(uuidv7())
FORMAT csv;text
4,7See UUID functions for generation, version extraction and timestamp extraction.