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:

  1. 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:

  1. 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.

  1. CREATE TABLE t_uuid (x UUID, y String) ENGINE=TinyLog
  1. INSERT INTO t_uuid SELECT generateUUIDv4(), 'Example 1'
  1. SELECT * FROM t_uuid
  1. ┌────────────────────────────────────x─┬─y─────────┐
  2. 417ddc5d-e556-4d27-95dd-a34d84e46a50 Example 1
  3. └──────────────────────────────────────┴───────────┘

Example 2

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

  1. INSERT INTO t_uuid (y) VALUES ('Example 2')
  1. SELECT * FROM t_uuid
  1. ┌────────────────────────────────────x─┬─y─────────┐
  2. 417ddc5d-e556-4d27-95dd-a34d84e46a50 Example 1
  3. 00000000-0000-0000-0000-000000000000 Example 2
  4. └──────────────────────────────────────┴───────────┘

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