©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

MySQL IS_UUID SQL Function - Valid UUID (Universal Unique Identifier)

IS_UUIDSyntax:IS_UUID(String)
Return value:INTEGER
Function type:Miscellaneous function
Function Description

The IS_UUID() function returns 1 if the "String" argument is a valid UUID in string format.

If "String" is not a valid UUID, the function returns 0.

If the value of "String" is NULL, the IS_UUID() function returns NULL.


Valid formats with hexadecimal values ​​are:

aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee

aaaaaaaabbbbccccddddeeeeeeeeeee

{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee}


This feature was introduced in MySQL 8.0 and later. It does not exist in MariaDB.

SQL Examples for the IS_UUID function

 1
 2
 3
 4
 5
 6
 7
 8

SELECT IS_UUID('decb92d4-d5bd-11ed-9a48-0800275588ea');
SELECT IS_UUID('decb92d4d5bd11ed9a480800275588ea');

SELECT IS_UUID('decb92d4d5bd-11ed-9a48-0800275588ea');
SELECT IS_UUID('');
SELECT IS_UUID(null);

IS_UUID('decb92d4-d5bd-11ed-9a48-0800275588ea')
bigint(1)
1
IS_UUID('decb92d4d5bd11ed9a480800275588ea')
bigint(1)
1
IS_UUID('decb92d4d5bd-11ed-9a48-0800275588ea')
bigint(1)
0
IS_UUID('')
bigint(1)
0
IS_UUID(null)
bigint(1)
NULL

Example of creating a replacement function for IS_UUID() in MariaDB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

/* Use MULTI-QUERY-Option in myway SQL manager */

DROP FUNCTION IF EXISTS IS_UUID;

CREATE FUNCTION IS_UUID(id varchar(128))
RETURNS integer

BEGIN

if id is null then 
    return null;
    else
    if char_length(id)=38 then 
        if substr(id, 1, 1)='{' and substr(id, 38, 1)='}' then 
            set id=substr(id, 2, 36); 
            end if;
        end if;
       
    if char_length(id)=36 then 
        if substr(id, 9, 1)='-' and substr(id, 14, 1)='-' and 
           substr(id, 19, 1)='-' and substr(id, 24, 1)='-' then
            set id=replace(id,'-',''); 
            end if;
        end if;
    if char_length(id)=32 then
        if unhex(id) is null then return 0; else return 1; end if;
        else
        return 0;
        end if;
    end if;
    
END;

SELECT IS_UUID('{decb92d4-d5bd-11ed-9a48-0800275588ea}');
SELECT IS_UUID('decb92d4-d5bd-11ed-9a48-0800275588ea');
SELECT IS_UUID('decb92d4d5bd11ed9a480800275588ea');

SELECT IS_UUID('XXXXXXXX-d5bd-11ed-9a48-0800275588ea');
SELECT IS_UUID('decb92d4d5bd-11ed-9a48-0800275588ea');
SELECT IS_UUID('');
SELECT IS_UUID(null);

IS_UUID('{decb92d4-d5bd-11ed-9a48-0800275588ea}')
int(11)
1
IS_UUID('decb92d4-d5bd-11ed-9a48-0800275588ea')
int(11)
1
IS_UUID('decb92d4d5bd11ed9a480800275588ea')
int(11)
1
IS_UUID('XXXXXXXX-d5bd-11ed-9a48-0800275588ea')
int(11)
0
IS_UUID('decb92d4d5bd-11ed-9a48-0800275588ea')
int(11)
0
IS_UUID('')
int(11)
0
IS_UUID(null)
int(11)
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the IS_UUID() function in MySQL and MariaDB databases

In MySQL and MariaDB the IS_UUID() function is used to check if a specific string is a valid UUID (Universally Unique Identifier). Where the function returns 1 if the string is a valid UUID and 0, if it is not, for example to validate user-supplied UUID values ​​before using them in database operations.

The IS_UUID() function can be used in combination with other query conditions to filter or query rows based on the validity of UUID values ​​stored in table columns, or to enforce the use of valid UUIDs in database triggers or constraints and maintain data integrity. When doing so, the function performs a basic syntax check on the provided string and ensures that it conforms to the UUID format. However, it does not check whether the string matches a known or existing UUID. Therefore, it is possible for IS_UUID() to validate strings that conform to the UUID format but are not necessarily valid.
INTERVALIS_IPV4IS_IPV6IS_UUIDISNULLLAST_INSERT_IDLAST_VALUE

Further MySQL und MariaDB SQL Miscellaneous functions

BIN_TO_UUIDBIN_TO_UUID(Binary string [, Swap])
More about BIN_TO_UUID Function

GET_LOCKGET_LOCK()

INET6_ATONINET6_ATON(String)
More about INET6_ATON Function

INET6_NTOAINET6_NTOA(Binary string)
More about INET6_NTOA Function

INET_ATONINET_ATON(String)
More about INET_ATON Function

INET_NTOAINET_NTOA(Value)
More about INET_NTOA Function

IS_FREE_LOCKIS_FREE_LOCK()

IS_IPV4IS_IPV4(String)
More about IS_IPV4 Function

IS_IPV4_COMPATIS_IPV4_COMPAT(String)

IS_IPV4_MAPPEDIS_IPV4_MAPPED(String)

IS_IPV6IS_IPV6(String)
More about IS_IPV6 Function

IS_USED_LOCKIS_USED_LOCK()

MASTER_GTID_WAITMASTER_GTID_WAIT()

MASTER_POS_WAITMASTER_POS_WAIT()

NAME_CONSTNAME_CONST(Name, Value)
More about NAME_CONST Function

RELEASE_ALL_LOCKSRELEASE_ALL_LOCKS()

RELEASE_LOCKRELEASE_LOCK()

SYS_GUIDSYS_GUID()
More about SYS_GUID Function

UUIDUUID()
More about UUID Function

UUID_SHORTUUID_SHORT()
More about UUID_SHORT Function

UUID_TO_BINUUID_TO_BIN(String [, Swap])
More about UUID_TO_BIN Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the IS_UUID SQL function: mysql.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer