Skip to main content
Version: V1.0.0

BIN_TO_UUID

Syntax

BIN_TO_UUID(binary_uuid), BIN_TO_UUID(binary_uuid,swap_flag)

Description

BIN_TO_UUID() converts a binary UUID to a string UUID and returns the result. The binary value binary_uuid should be a UUID of type VARBINARY(16). The returned value is a 128-bit number that conforms to UUID version 1. It is a utf8mb3 string consisting of five hexadecimal numbers separated by hyphens. The format is the same as that of the UUID() function, which is aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeeee. The following table describes the format:

  • The first three numbers are generated from the low, middle, and high parts of the timestamp. The high part also includes the UUID version number.
  • The fourth number ensures the uniqueness of the timestamp. This is necessary in case the timestamp value is not unique (for example, due to daylight saving time).
  • The fifth number is the IEEE 802 node number that ensures 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- and double-parameter forms. The following table describes the forms:

  • The single-parameter form specifies a binary UUID value. It is assumed that the time low and time high parts of the UUID value are not swapped. The string result is in the same order as the binary parameter.
  • The double-parameter form specifies a binary UUID value and a swap_flag value:
    • If swap_flag is 0, the double-parameter form is equivalent to the single-parameter form. The string result is in the same order as the binary parameter.
    • If swap_flag is 1, it is assumed that the time low and time high parts of the UUID value are swapped. These parts are swapped back to their original positions in the result value.

BIN_TO_UUID() is the inverse function of UUID_TO_BIN(). For usage examples and rules for swapping the time parts, see UUID_TO_BIN().