UUID Functions

These apply to MonetDB SQL type: UUID (Universally Unique IDentifiers).

FunctionReturn typeDescriptionExampleResult
isauuid(string)booleantests if the given varchar string represents a valid uuid value and returns boolean true or false, or null when the input is nullSELECT isauuid( 'e31960fb-dc8b-452d-ab30-b342723e7565');true
uuid()uuidgenerates and returns a new random uuidSELECT uuid();65950c76-a2f6-4543-660a-b849cf5f2453
uuid(integer)uuidgenerates one new random uuid so it can be called for a column. The integer argument is needed but not used.SELECT uuid(3);1274d7b5-7506-488c-83be-95c3c97d24f0

The behavioral difference between uuid() and uuid(integer) is shown by below query:

SELECT row, uuid() AS different_uuids, uuid(0) AS same_uuids
  FROM (VALUES(1), (2), (3)) AS t(row);

It returns result table:

rowdifferent_uuidssame_uuids
1aad66a60-a860-4642-9bfd-b5cee00690a31274d7b5-7506-488c-83be-95c3c97d24f0
277d33da6-889c-4823-8bff-bb104a368c6f1274d7b5-7506-488c-83be-95c3c97d24f0
396affa90-08fe-4da0-bef8-3decf3f6e4d71274d7b5-7506-488c-83be-95c3c97d24f0

 

 

To convert a varchar string column (or expression or literal which represents a valid uuid) to a uuid type, you can use a cast() or convert() function. Examples:

SELECT    CAST('26d7a80b-7538-4682-a49a-9d0f9676b765' as uuid) AS uuid_val;
SELECT CONVERT('83886744-d558-4e41-a361-a40b2765455b', uuid)   AS uuid_val;

 

To convert a quoted string literal which represents a valid uuid to a uuid type you can also use the uuid casting prefix. Example:

SELECT uuid 'AC6E4E8C-81B5-41B5-82DE-9C837C23B40A'  AS uuid_val;