Built-in Functions
KalamDB provides several built-in functions for ID generation, user context, and timestamps.
ID Generation
SNOWFLAKE_ID()
Generate a unique 64-bit snowflake ID (time-ordered, globally unique):
SELECT SNOWFLAKE_ID();
-- Returns: 7302451094528000001Commonly used as the default for primary keys:
CREATE TABLE app.messages (
id BIGINT PRIMARY KEY DEFAULT SNOWFLAKE_ID(),
content TEXT NOT NULL
);UUID_V7()
Generate a UUIDv7 (time-ordered UUID):
SELECT UUID_V7();
-- Returns: 0193a5e0-7a1b-7000-8000-000000000001ULID()
Generate a ULID (Universally Unique Lexicographically Sortable Identifier):
SELECT ULID();
-- Returns: 01HQJK5M5R3YJQWXHN4QWXYN01Context Functions
CURRENT_USER()
Returns the username of the currently authenticated user:
SELECT CURRENT_USER();
-- Returns: 'alice'Useful for audit columns:
CREATE TABLE app.audit_log (
id BIGINT PRIMARY KEY DEFAULT SNOWFLAKE_ID(),
action TEXT NOT NULL,
performed_by TEXT DEFAULT CURRENT_USER(),
created_at TIMESTAMP DEFAULT NOW()
);Date & Time
NOW()
Returns the current timestamp:
SELECT NOW();
-- Returns: 2026-02-18T10:30:00.000ZCommonly used as a default for timestamp columns:
CREATE TABLE app.events (
id BIGINT PRIMARY KEY DEFAULT SNOWFLAKE_ID(),
event_type TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);Function Summary
| Function | Return Type | Description |
|---|---|---|
SNOWFLAKE_ID() | BIGINT | Time-ordered 64-bit unique ID |
UUID_V7() | TEXT | Time-ordered UUID v7 |
ULID() | TEXT | Lexicographically sortable unique ID |
CURRENT_USER() | TEXT | Authenticated username |
NOW() | TIMESTAMP | Current server timestamp |
Last updated on