UUID_TO_INT
Description
The UUID_TO_INT function converts a UUID string to its INT128 integer representation. This is useful for scenarios where UUIDs need to be stored as integers in the database.
Syntax
UUID_TO_INT(<uuid>)
Parameters
| Parameter | Description |
|---|---|
<uuid> | UUID string to convert. Type: VARCHAR |
Return Value
Returns INT128 type, the integer representation of the UUID.
Special cases:
- If parameter is NULL, returns NULL
- If UUID format is invalid, returns NULL
Examples
- Basic usage: UUID to integer
SELECT uuid_to_int('6ce4766f-6783-4b30-b357-bba1c7600348');
+-----------------------------------------------------+
| uuid_to_int('6ce4766f-6783-4b30-b357-bba1c7600348') |
+-----------------------------------------------------+
| 95721955514869408091759290071393952876 |
+-----------------------------------------------------+
- NULL value handling
SELECT uuid_to_int(NULL);
+-------------------+
| uuid_to_int(NULL) |
+-------------------+
| NULL |
+-------------------+
- Using with UUID()
SELECT uuid_to_int(UUID());
+----------------------------------------+
| uuid_to_int(UUID()) |
+----------------------------------------+
| 65543688548341017423158579845706592446 |
+----------------------------------------+
- Batch conversion
SELECT uuid, uuid_to_int(uuid) AS uuid_int
FROM (SELECT '6ce4766f-6783-4b30-b357-bba1c7600348' AS uuid) t;
+--------------------------------------+--------------------------------------+
| uuid | uuid_int |
+--------------------------------------+--------------------------------------+
| 6ce4766f-6783-4b30-b357-bba1c7600348 | 95721955514869408091759290071393952876|
+--------------------------------------+--------------------------------------+
- Uppercase UUID conversion
SELECT uuid_to_int('6CE4766F-6783-4B30-B357-BBA1C7600348');
+-----------------------------------------------------+
| uuid_to_int('6CE4766F-6783-4B30-B357-BBA1C7600348') |
+-----------------------------------------------------+
| 95721955514869408091759290071393952876 |
+-----------------------------------------------------+
- Invalid UUID format
SELECT uuid_to_int('invalid-uuid-format');
+------------------------------------+
| uuid_to_int('invalid-uuid-format') |
+------------------------------------+
| NULL |
+------------------------------------+
Keywords
UUID_TO_INT