跳到主要内容
版本:0.2.x

UUID

Notice: Some of the examples below are referenced from ClickHouse Documentation but have been adapted and modified to work in ByConity.

generateUUIDv4

Generates the UUID of version 4 .

Syntax


generateUUIDv4()

Returned value

  • The UUID type value.

Examples This example demonstrates creating a table with the UUID type column and inserting a value into the table.


CREATE TABLE test.functionGenerateUUIDv4 (x UUID) ENGINE=CnchMergeTree ORDER BY x;
INSERT INTO test.functionGenerateUUIDv4 SELECT generateUUIDv4();
SELECT * FROM test.functionGenerateUUIDv4;
┌─x────────────────────────────────────┐
│ a630fbcb-1a32-4902-b5cc-dd51eba8cf4b │
└──────────────────────────────────────┘

toUUID

Converts String type value to UUID type. Exception will be raised if input string is invalid uuid format.

Syntax


toUUID(String)

Arguments

  • String — string in uuid format.

Returned value

  • The UUID type value.

Examples


SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') AS uuid, toTypeName(uuid) AS uuid_type;
┌─uuid─────────────────────────────────┬─uuid_type─┐
│ 61f0c404-5cb3-11e7-907b-a6006ad3dba0 │ UUID │
└──────────────────────────────────────┴───────────┘

toUUIDOrNull

It takes an argument of type String and tries to parse it into UUID. If failed, returns NULL.

Syntax


toUUIDOrNull(String)

Arguments

  • String — string in uuid format.

Returned value

  • The Nullable(UUID) type value.

Examples


SELECT toUUIDOrNull('61f0c404-5cb3-11e7-907b-a6006ad3dba0T') AS uuid
┌─uuid─┐
│ ᴺᵁᴸᴸ │
└──────┘

toUUIDOrZero

It takes an argument of type String and tries to parse it into UUID. If failed, returns zero UUID.

Syntax


toUUIDOrZero(String)

Arguments

  • String — string in uuid format.

Returned value

  • The UUID type value.

Examples


SELECT toUUIDOrZero('61f0c404-5cb3-11e7-907b-a6006ad3dba0T') AS uuid
┌─uuid─────────────────────────────────┐
│ 00000000-0000-0000-0000-000000000000 │
└──────────────────────────────────────┘

generateUUIDv4

Generates the UUID of version 4 .

Syntax


generateUUIDv4()

Returned value

The UUID type value.

Usage 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─┐

│ f4bf890f-f9dc-4332-ad5c-0c18e73f28e9 │

└──────────────────────────────────────┘

toUUID

Syntax


toUUID (x)

Converts String type value to UUID type.


toUUID(String)

Returned value

The UUID type value.

Usage example


SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') AS uuid


┌─────────────────────────────────uuid─┐

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

└──────────────────────────────────────┘

toUUIDOrNull

toUUIDOrNull (x)

It takes an argument of type String and tries to parse it into UUID. If failed, returns NULL.


toUUIDOrNull(String)

Returned value

The Nullable(UUID) type value.

Usage example


SELECT toUUIDOrNull('61f0c404-5cb3-11e7-907b-a6006ad3dba0T') AS uuid


┌─uuid─┐

│ ᴺᵁᴸᴸ │

└──────┘

toUUIDOrZero

toUUIDOrZero (x)

It takes an argument of type String and tries to parse it into UUID. If failed, returns zero UUID.


toUUIDOrZero(String)

Returned value

The UUID type value.

Usage example


SELECT toUUIDOrZero('61f0c404-5cb3-11e7-907b-a6006ad3dba0T') AS uuid


┌─────────────────────────────────uuid─┐

│ 00000000-0000-0000-0000-000000000000 │

└──────────────────────────────────────┘