These apply to MonetDB SQL type: UUID (Universally Unique IDentifiers).
| Function | Return type | Description | Example | Result |
|---|---|---|---|---|
isauuid(string) | boolean | tests if the given varchar string represents a valid uuid value and returns boolean true or false, or null when the input is null | SELECT isauuid( 'e31960fb-dc8b-452d-ab30-b342723e7565'); | true |
uuid() | uuid | generates and returns a new random uuid | SELECT uuid(); | 65950c76-a2f6-4543-660a-b849cf5f2453 |
uuid(integer) | uuid | generates 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:
| row | different_uuids | same_uuids |
|---|---|---|
| 1 | aad66a60-a860-4642-9bfd-b5cee00690a3 | 1274d7b5-7506-488c-83be-95c3c97d24f0 |
| 2 | 77d33da6-889c-4823-8bff-bb104a368c6f | 1274d7b5-7506-488c-83be-95c3c97d24f0 |
| 3 | 96affa90-08fe-4da0-bef8-3decf3f6e4d7 | 1274d7b5-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;