UUID Data Type
Universally Unique Identifier data type. This type is optimized for storing 128-bit UUID values efficiently.
Syntax
UUIDDescription
The UUID data type is intended for the storage of 128-bit UUID (Universally Unique Identifier) data. See the UUID function page for more details on UUIDs themselves.
Retrieval
Data retrieved by this data type is in the string representation defined in RFC4122.
Casting
String literals of hexadecimal characters and CHAR/VARCHAR/TEXT can be cast to the UUID data type. Likewise hexadecimal literals, binary-literals, and BINARY/VARBINARY/BLOB types can also be cast to UUID.
The data type will not accept a short UUID generated with the UUID_SHORT function, but will accept a value without the - character generated by the SYS_GUID function (or inserted directly). Hyphens can be partially omitted as well, or included after any group of two digits.
The type does not accept UUID values in braces, permitted by some implementations.
Storage
UUID values are stored in an index-friendly manner; the order of a UUID of llllllll-mmmm-Vhhh-vsss-nnnnnnnnnnnn is stored as:
This provides a sorting order, assuming a UUIDv1 (node and timestamp) is used, of the node, followed by the timestamp. The key aspect is the timestamps are sequential.
MariaDB starting with 10.10
Taking into account that UUIDv7 and other versions are designed around time ordering, UUID values version >= 6 are stored without byte-swapping, and UUID values with version >=8 and variant=0 are now considered invalid (as the SQL standard suggests).
UUID values version >= 6 are not stored without byte-swapping, and UUID values with version >=8 and variant=0 are not considered invalid.
Examples
Directly inserting via string literals:
Directly Inserting via hexadecimal literals:
Generating and inserting via the UUID function.
Retrieval:
The UUID_SHORT function does not generate valid full-length UUID:
Accepting a value without the - character, either directly or generated by the SYS_GUID function:
Valid and invalid hyphen and brace usage:
See Also
10.7 preview feature: UUID Data Type (mariadb.org blog post)
UUID function for generating v1 UUIDs
UUID function for generating v4 UUIDs
UUID function for generating v7 UUIDs
SYS_GUID - UUID without the
-character for Oracle compatibility
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?

