UUID

A universally unique identifier (UUID) is a 16-byte number used to identify records. For detailed information about the UUID, see Wikipedia.

The example of UUID type value is represented below:

61f0c404-5cb3-11e7-907b-a6006ad3dba0

If you do not specify the UUID column value when inserting a new record, the UUID value is filled with zero:

00000000-0000-0000-0000-000000000000

How to generate

To generate the UUID value, ClickHouse provides the generateUUIDv4 function.

Usage example

Example 1

This example demonstrates creating a table with the UUID type column and inserting 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

┌────────────────────────────────────x─┬─y─────────┐
 417ddc5d-e556-4d27-95dd-a34d84e46a50  Example 1 
└──────────────────────────────────────┴───────────┘

Example 2

In this example, the UUID column value is not specified when inserting a new record.

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

:) SELECT * FROM t_uuid

┌────────────────────────────────────x─┬─y─────────┐
 417ddc5d-e556-4d27-95dd-a34d84e46a50  Example 1 
 00000000-0000-0000-0000-000000000000  Example 2 
└──────────────────────────────────────┴───────────┘

Restrictions

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.

Original article