Skip to content

UUID

The UUID data type stores 128-bit Universally Unique Identifiers. See also sys.gen_random_uuid().

A UUID is a sequence of lower-case hexadecimal digits. Each UUID forms five groups of digits, and each group is separated by a hyphen: a group of 8 digits, three groups of 4 digits, and a group of 12 digits. This sequence makes a total of 32 digits representing 128 bits. For example:

653dfdba-f044-42a2-9000-199945f61dce

Alternative input forms are accepted: the use of uppercase digits, the standard format surrounded by braces, omission of some or all hyphens, an additional hyphen after any group of four digits. For example:

653DFDBA-F044-42A2-9000-199945F61DCE
{653dfdba-f044-42a2-9000-199945f61dce}
653dfdbaf04442a29000199945f61dce
653d-fdba-f044-42a2-9000-1999-45f6-1dce
653dfdba-f04442a2-90001999-45f61dce

The output is always in the standard form, regardless of the input format.

premdb=# \d uuidtest
  Table "public.uuidtest"
 Column  | Type | Modifiers 
---------+------+-----------
 uuidcol | uuid | 

Distribution: Hash (uuidcol)

premdb=# insert into uuidtest values('653dfdba-f04442a2-90001999-45f61dce');
INSERT 0 1

premdb=# select distinct uuidcol from uuidtest where uuidcol='653dfdba-f04442a2-90001999-45f61dce';
              uuidcol                
--------------------------------------
 653dfdba-f044-42a2-9000-199945f61dce
(1 row)

Note: You cannot select UUID values based on a LIKE condition. Instead, use a condition with a comparison operator such as >= and fill in the unknown digits with zeroes. For example:

premdb=# select * from uuidtest where c1 >= '653dfdba-0000-0000-0000-000000000000';
                 c1                  
--------------------------------------
 653dfdba-f044-42a2-9000-199945f61dce
(1 row)

Parent topic:SQL Data Types