UUID_STR Function
Converts any
universally unique identifier (UUID) into a
well-formed, canonically formatted string like "491bf00b-7166-4c78-be23-4cfc15f72e86".
Syntax
UUID_STR(input)
Parameters
- input: text or blob
If input is text, then it must contain exactly 32 hexadecimal digits (0-9, A-F). Optionally, it may contain
hyphens to separate blocks of digits and curly braces at the beginning and end. If input is a blob, then it
must be exactly 16 bytes.
Return Value
The
input reformatted into a 36-character string like
"491bf00b-7166-4c78-be23-4cfc15f72e86". If
input is not a valid UUID, then
NULL is returned.
Example
-- These all print the same thing: 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
PRINT UUID_STR('A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11');
PRINT UUID_STR('{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}');
PRINT UUID_STR('a0eebc999c0b4ef8bb6d6bb9bd380a11');
PRINT UUID_STR('a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11');
PRINT UUID_STR('{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}');
-- Prints 1, because 'foobar' is not a valid UUID.
PRINT UUID_STR('foobar') IS NULL;
-- Prints 1, because the blob returned by ARRAY() is not a UUID.
PRINT UUID_STR(ARRAY(1, 2, 3)) IS NULL;