# UUID Functions

# generateUUIDv4

Generates the UUID of version 4.

Syntax

generateUUIDv4([x])

Arguments

  • x — Expression resulting in any of the supported data types. The resulting value is discarded, but the expression itself if used for bypassing common subexpression elimination if the function is called multiple times in one query. Optional parameter.

Returned value

  • The UUID type value.

Example

  • This example demonstrates creating a table with the UUID type column and inserting a value into the table.
CREATE TABLE t_uuid (x UUID) ENGINE=TinyLog;
INSERT INTO t_uuid SELECT generateUUIDv4();
SELECT  FROM t_uuid;
┌────────────────────────────────────x─┐
│ bba9f24d-c056-4482-ba63-6f1216ed0e73 │
└──────────────────────────────────────┘
  • generate multiple values in one row
SELECT generateUUIDv4(1), generateUUIDv4(2)
┌─generateUUIDv4(1)────────────────────┬─generateUUIDv4(2)────────────────────┐
│ c6518cf3-9048-4198-b94c-72c7c2990535 │ dd45d634-f3cf-4262-b6eb-b16f77d40fe3 │
└──────────────────────────────────────┴──────────────────────────────────────┘

# toUUID

Converts String type value to UUID type.

toUUID(String)

Returned value

The UUID type value.

Example

SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') AS uuid
┌─uuid─────────────────────────────────┐
│ 61f0c404-5cb3-11e7-907b-a6006ad3dba0 │
└──────────────────────────────────────┘
Last Updated: Sat Apr 13 2024 10:45:55 GMT+0000