8.7. UUID Functions

8.7.1. CHAR_TO_UUID()

Converts a string UUID to its binary representation

Result typeBINARY(16)

Syntax

CHAR_TO_UUID (ascii_uuid)

Table 8.76. CHAR_TO_UUID Function Parameter
ParameterDescription

ascii_uuid

A 36-character representation of UUID. - (hyphen) in positions 9, 14, 19 and 24; valid hexadecimal digits in any other positions, e.g. 'A0bF4E45-3029-2a44-D493-4998c9b439A3'

Converts a human-readable 36-char UUID string to the corresponding 16-byte UUID.

8.7.1.1. CHAR_TO_UUID Examples

select char_to_uuid('A0bF4E45-3029-2a44-D493-4998c9b439A3') from rdb$database
-- returns A0BF4E4530292A44D4934998C9B439A3 (16-byte string)
 
select char_to_uuid('A0bF4E45-3029-2A44-X493-4998c9b439A3') from rdb$database
-- error: -Human readable UUID argument for CHAR_TO_UUID must
--         have hex digit at position 20 instead of "X (ASCII 88)"

See alsoSection 8.7.3, “UUID_TO_CHAR()”, Section 8.7.2, “GEN_UUID()”

8.7.2. GEN_UUID()

Generates a version 4 or version 7 random UUID

Result typeBINARY(16)

Syntax

GEN_UUID ( [version] )

Table 8.77. GEN_UUID Function Parameter
ParameterDescription

version

The UUID version. Only 4 and 7 are accepted. The default is 4, if not specified.

Returns a version 4 or version 7 universally unique ID (UUID) as a 16-byte binary string. The string format (Section 8.7.3, “UUID_TO_CHAR()”) of a version 4 or 7 UUID is XXXXXXXX-XXXX-YXXX-ZXXX-XXXXXXXXXXXX, where Y is the version (4 or 7) and Z is 8, 9, A or B.

Table 8.78. Supported versions

4

UUID from truly random or pseudorandom numbers (except version and variant bits)

7

UUID with the first 48 bits milliseconds since midnight 1 Jan 1970 UTC (Unix Epoch), and the remaining 74 bits — except version and variant bits — from truly random or pseudorandom numbers

Version 7 has the advantage that the UUID value is time-ordered (with millisecond precision).

Other UUID versions are not supported by GEN_UUID.

See also RFC 9562 — Universally Unique IDentifiers (UUIDs)

8.7.2.1. GEN_UUID Example

-- Implicit version 4
select gen_uuid() from rdb$database;
-- Example: 701396BB8E814F9681BA88B6F4AEF3B7
 
-- Explicit version 4
select gen_uuid(4) from rdb$database;
-- Example: F6034BC70DE142C0BA2D81F40FDD7579
 
-- Explicit version 7
select gen_uuid(7) from rdb$database;
-- Example: 019C51802A227E9DB1F9E495396B9A9F

See alsoSection 8.7.3, “UUID_TO_CHAR()”, Section 8.7.1, “CHAR_TO_UUID()”

8.7.3. UUID_TO_CHAR()

Converts a binary UUID to its string representation

Result typeCHAR(36)

Syntax

UUID_TO_CHAR (uuid)

Table 8.79. UUID_TO_CHAR Function Parameters
ParameterDescription

uuid

16-byte UUID

Converts a 16-byte UUID to its 36-character, human-readable ASCII representation.

8.7.3.1. UUID_TO_CHAR Examples

select uuid_to_char(x'876C45F4569B320DBCB4735AC3509E5F') from rdb$database;
-- returns '876C45F4-569B-320D-BCB4-735AC3509E5F';
 
select uuid_to_char(gen_uuid()) from rdb$database
-- returns e.g. '98044252-7012-4960-9152-C5972528A2BB'

See alsoSection 8.7.1, “CHAR_TO_UUID()”, Section 8.7.2, “GEN_UUID()”