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;
                  id                  
--------------------------------------
 32cee028-940a-42d8-a2ed-1a6ab8d7b5cc
 20157067-99ab-4a02-9816-877f8bdb57ee
 a3108569-3ce7-4f7c-b650-1f7b2b5012b3
(3 rows)

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

Input

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}';