UUID Functions
This page provides reference information for the UUID-related functions in TiDB Cloud Lake. These functions generate and work with Universally Unique Identifiers (UUIDs).
UUID Generation Functions
Usage Examples
Generating Primary Keys
-- Create a table with UUID primary key
CREATE TABLE users (
id UUID DEFAULT GEN_RANDOM_UUID(),
username VARCHAR,
email VARCHAR,
PRIMARY KEY(id)
);
-- Insert data without specifying UUID
INSERT INTO users (username, email)
VALUES ('johndoe', 'john@example.com');
-- Query to see the auto-generated UUID
SELECT * FROM users;
Creating Unique Identifiers for Distributed Systems
-- Generate multiple UUIDs for distributed event tracking
SELECT
GEN_RANDOM_UUID() AS event_id,
'user_login' AS event_type,
NOW() AS event_time
FROM numbers(5);
UUID Version Information
TiDB Cloud Lake's UUID implementation has evolved:
- Version 1.2.658 and later: Uses UUID version 7, which includes timestamp information for chronological sorting
- Prior to version 1.2.658: Used UUID version 4, which was purely random