Function to generate a UUID string
The random_uuid function is used to generate a random UUID (Universally Unique Identifier), returned as a 36-character string.
This is particularly useful for generating unique primary keys, especially in multi-region tables and scenarios where the generation of unique IDs for a record must be idempotent.
Example:
CREATE TABLE myTable ( id STRING AS UUID, name STRING, PRIMARY KEY (id));
INSERT INTO myTable VALUES (random_uuid(), 'John');
select * from myTable;Explanation: The random_uuid() function used while inserting a row, generates a random 36-character UUID.
{"id":"9678dc87-a21d-4327-a149-51594e967438","name":"John"}
1 row returned