Syntax
BIN_TO_UUID(binary_uuid), BIN_TO_UUID(binary_uuid,swap_flag)
Purpose
The BIN_TO_UUID() function converts a binary UUID to a string UUID and returns the result. The binary value binary_uuid should be a UUID of the VARBINARY(16) data type. The returned value conforms to the UUID version 1 format, which is a 128-bit number represented as a utf8mb3 string consisting of five hexadecimal groups separated by hyphens. The format is the same as the UUID() function, which is aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeeee. The format is described as follows:
- The first three groups are generated from the low, middle, and high parts of the timestamp. The high part also includes the UUID version number.
- The fourth group is reserved to ensure uniqueness in case the timestamp value is not unique (for example, due to daylight saving time).
- The fifth group is the IEEE 802 node number, which provides spatial uniqueness. If unavailable, a random number is used instead, but spatial uniqueness cannot be guaranteed.
If the UUID parameter is NULL, the returned value is NULL. An error occurs if any parameter is invalid.
The syntax of BIN_TO_UUID() includes both single-parameter and double-parameter forms, as described below:
- The single-parameter form specifies the binary UUID value. The UUID value is assumed to not have its low and high timestamp parts swapped. The returned string result maintains the same order as the binary parameter.
- The double-parameter form specifies the binary UUID value and the
swap_flagvalue:- If
swap_flagis 0, the double-parameter form is equivalent to the single-parameter form. The string result maintains the same order as the binary parameter. - If
swap_flagis 1, the UUID value is assumed to have its low and high timestamp parts swapped. These parts are swapped back to their original positions in the result value.
- If
BIN_TO_UUID() is the inverse function of UUID_TO_BIN(). For information about its usage examples and the rules for swapping the timestamp parts, see UUID_TO_BIN().
