This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MySQL: convert GUID (Microsoft-style UUID) to BINARY(16) | |
# '11223344-5566-7788-9900-AABBCCDDEEFF' → 0x44332211665588779900AABBCCDDEEFF | |
# Usage: CREATE TABLE example (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, guid BINARY(16) NOT NULL UNIQUE); | |
# INSERT INTO example (guid) VALUES (uuid_to_bin(UUID())); | |
# Tested on: MySQL 5.6, 5.7, 8.0 | |
CREATE FUNCTION uuid_to_bin(s CHAR(36)) | |
RETURNS binary(16) | |
DETERMINISTIC | |
RETURN UNHEX(CONCAT( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MySQL: convert BINARY(16) to GUID (Microsoft-style UUID) | |
# 0x11223344556677889900AABBCCDDEEFF → '44332211-6655-8877-9900-AABBCCDDEEFF' | |
# Usage: CREATE TABLE example (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, guid BINARY(16) NOT NULL UNIQUE); | |
# SELECT id, uuid_from_bin(guid) FROM example; | |
# Tested on: MySQL 5.6, 5.7, 8.0 | |
CREATE FUNCTION uuid_from_bin(b BINARY(16)) | |
RETURNS char(36) CHARSET utf8 | |
DETERMINISTIC | |
BEGIN |