Universally Unique Identifier - UUID

The pre-defined schema BUILTIN contains the following user-defined type to store unique identifier data:

Type

SQL type

Description

builtin.uuid

BINARY(16)

 

The following routines belong to the uuid user-defined type:

Routine

Routine type

Description

BUILTIN.UUID_NEW()

Function

Generates a new uuid value, which with very high probability is globally unique.

BUILTIN.UUID_FROM_
TEXT(HEXSTRING)

Function

Converts a hexadecimal string to an uuid value.

The HEXSTRING argument should follow the standard format hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh, where each h is a hexadecimal value represented by using the characters 0-9 and a-f.

AS_TEXT

Instance method

Converts a uuid value to a character representation, using the UUID standard format.

Example

Create a table and insert a few values:

create table tuuid (uuid builtin.uuid);

 

insert into tuuid values (builtin.uuid_new());

insert into tuuid values (builtin.uuid_new());

 

select uuid.as_text() from tuuid;

 

====================================

039f01f0-a635-11e8-9f4c-aa0004007a04

04494bb0-a635-11e8-9f4c-aa0004007a04

 

It is also possible to insert uuid values explicitly, either by using a binary constant or converting a character string using the function bultin.uuid_from_text.

insert into tuuid values (x'62E4BD10A63711E8A174AA0004007A04');

insert into tuuid values
    (builtin.uuid_from_text('85dc2790-a637-11e8-a174-aa0004007a04'));

 

Create an index to improve search performance:

create index tuuid_ix on tuuid (uuid);

 

select * from tuuid where uuid =

    builtin.uuid_from_text('85dc2790-a637-11e8-a174-aa0004007a04'));

 

More information about uuid can be found at https://en.wikipedia.org/wiki/Universally_unique_identifier