Skip to main content


A Universally Unique Identifier (UUID) is a 16-byte value used to identify records. For detailed information about UUIDs, see Wikipedia.

While different UUID variants exist (see here), ClickHouse does not validate that inserted UUIDs conform to a particular variant. UUIDs are internally treated as a sequence of 16 random bytes with 8-4-4-4-12 representation at SQL level.

Example UUID value:


The default UUID is all-zero. It is used, for example, when a new record is inserted but no value for a UUID column is specified:


Generating UUIDs

ClickHouse provides the generateUUIDv4 function to generate random UUID version 4 values.

Usage Example

Example 1

This example demonstrates the creation of a table with a UUID column and the insertion of a value into the table.

CREATE TABLE t_uuid (x UUID, y String) ENGINE=TinyLog

INSERT INTO t_uuid SELECT generateUUIDv4(), 'Example 1'

SELECT * FROM t_uuid


│ 417ddc5d-e556-4d27-95dd-a34d84e46a50 │ Example 1 │

Example 2

In this example, no UUID column value is specified when the record is inserted, i.e. the default UUID value is inserted:

INSERT INTO t_uuid (y) VALUES ('Example 2')

SELECT * FROM t_uuid
│ 417ddc5d-e556-4d27-95dd-a34d84e46a50 │ Example 1 │
│ 00000000-0000-0000-0000-000000000000 │ Example 2 │


The UUID data type only supports functions which String data type also supports (for example, min, max, and count).

The UUID data type is not supported by arithmetic operations (for example, abs) or aggregate functions, such as sum and avg.