UUID Functions
Vector implements the following SQL procedures to create, convert, and compare UUIDs:
• UUID_CREATE( )
• UUID_COMPARE(uuid1, uuid2)
• UUID_TO_CHAR(u)
• UUID_FROM_CHAR(c)
UUID_CREATE( ) Function
The UUID_CREATE() function creates a 128 bit UUID:
> createdb uuiddb
> sql uuiddb
* uuidtable (u1 BYTE (16), u2 BYTE(16));
* INSERT INTO uuidtable VALUES (UUID_CREATE(), UUID_CREATE());
//
// Verify the length in byte format
//
* SELECT LENGTH(u1) FROM uuidtable;
//
//Length returned equals 16 bytes
//
UUID_COMPARE(uuid1, uuid2) Function
The UUID_COMPARE(uuid1, uuid2) function returns an integer value:
//
// Determine if u1 is greater than, less than, or equal to u2
//
* SELECT UUID_COMPARE(u1, u2) FROM uuidtable;
//
// u1 > u2
//
UUID_TO_CHAR(u) Function
The UUID_TO_CHAR(u) function converts a generated UUID into its character representation.
* SELECT UUID_TO_CHAR(u1) FROM uuidtable;
//
// Verify length of UUID in character format
//
* SELECT LENGTH(UUID_TO_CHAR(u1)) FROM uuidtable;
//
//A UUID contains 36 characters
//
UUID_FROM_CHAR(c) Function
The UUID_FROM_CHAR(c) function converts a UUID from its character representation into byte representation:
//
// Insert a UUID in character format into a table
//
* uuidtochar
AS
SELECT UUID_TO_CHAR(u1) AS c1 FROM uuidtable;
* SELECT c1 FROM uuidtochar;
//
// convert UUID into byte representation
//
* SELECT UUID_FROM_CHAR(c1) FROM uuidtochar;