Reference: UUID Type

UUIDs are universally unique identifiers that can be used as synthetic keys in tables. Each UUID is a 128 bit value that is generated by an algorithm specified in RFC 4122 that gives a very high probability of having no collisions.


As an alternative to UUIDs, consider using auto-incrementing integer IDs smaller than 16 Bytes. E.g.:

create table foo(id integer generated always as identity)

Usage Example

create table example (
    id uuid default gen_random_uuid()
insert into example select from generate_series(1, 3);
select id from example;
(3 rows)

UUIDs are stored as 16 Bytes, but always displayed as 32 standard hexadecimal characters.


UUIDs are case and hyphen insensitive and can be surrounded by braces:

-- All of the following literals are equivalent
select uuid 'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11';
select uuid '{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}';
select uuid 'a0eebc999c0b4ef8bb6d6bb9bd380a11';
select uuid 'a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11';
select uuid '{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}';