Overview
YCQL provides a comprehensive set of built-in functions for data manipulation, type conversion, UUID generation, and timestamp operations.Aggregate Functions
Aggregate functions operate on a set of rows and return a single value.COUNT
Counts the number of rows or non-null values. Syntax:SUM
Calculates the sum of numeric values. Syntax:MIN
Returns the minimum value. Syntax:MAX
Returns the maximum value. Syntax:AVG
Calculates the average of numeric values. Syntax:UUID and TimeUUID Functions
uuid()
Generates a random UUID (version 4). Syntax:now()
Generates a new TimeUUID (version 1) with the current timestamp. Syntax:now() generates a unique TimeUUID with the current timestamp and a random component.
minTimeuuid()
Generates the minimum possible TimeUUID for a given timestamp. Syntax:timestamp: TIMESTAMP value or milliseconds since epoch
maxTimeuuid()
Generates the maximum possible TimeUUID for a given timestamp. Syntax:timestamp: TIMESTAMP value or milliseconds since epoch
Timestamp Functions
toTimestamp()
Converts a TimeUUID to a TIMESTAMP. Syntax:currentTimestamp()
Returns the current timestamp with microsecond precision. Syntax:cql_revert_to_partial_microsecond_support=true (default), timestamps include microsecond precision.
toUnixTimestamp()
Converts a TimeUUID or TIMESTAMP to Unix timestamp (milliseconds since epoch). Syntax:unixTimestampOf()
Alias fortoUnixTimestamp() - converts TimeUUID to Unix timestamp.
Syntax:
Type Conversion Functions - To Blob
Convert various data types to BLOB format.booleanAsBlob()
Syntax:booleanAsBlob(boolean_value)
Example:
tinyIntAsBlob()
Syntax:tinyIntAsBlob(tinyint_value)
Example:
smallIntAsBlob()
Syntax:smallIntAsBlob(smallint_value)
Example:
intAsBlob()
Syntax:intAsBlob(int_value)
Example:
bigIntAsBlob()
Syntax:bigIntAsBlob(bigint_value)
Example:
floatAsBlob()
Syntax:floatAsBlob(float_value)
Example:
doubleAsBlob()
Syntax:doubleAsBlob(double_value)
Example:
textAsBlob() / varcharAsBlob()
Syntax:textAsBlob(text_value) or varcharAsBlob(varchar_value)
Example:
timestampAsBlob()
Syntax:timestampAsBlob(timestamp_value)
Example:
uuidAsBlob()
Syntax:uuidAsBlob(uuid_value)
Example:
timeuuidAsBlob()
Syntax:timeuuidAsBlob(timeuuid_value)
Example:
Type Conversion Functions - From Blob
Convert BLOB format back to various data types.blobAsBoolean()
Syntax:blobAsBoolean(blob_value)
Example:
blobAsTinyInt()
Syntax:blobAsTinyInt(blob_value)
Example:
blobAsSmallInt()
Syntax:blobAsSmallInt(blob_value)
Example:
blobAsInt()
Syntax:blobAsInt(blob_value)
Example:
blobAsBigInt()
Syntax:blobAsBigInt(blob_value)
Example:
blobAsFloat()
Syntax:blobAsFloat(blob_value)
Example:
blobAsDouble()
Syntax:blobAsDouble(blob_value)
Example:
blobAsText() / blobAsVarchar()
Syntax:blobAsText(blob_value) or blobAsVarchar(blob_value)
Example:
blobAsTimestamp()
Syntax:blobAsTimestamp(blob_value)
Example:
blobAsUuid()
Syntax:blobAsUuid(blob_value)
Example:
blobAsTimeuuid()
Syntax:blobAsTimeuuid(blob_value)
Example:
Practical Examples
Working with Blobs in Collections
Time-Based Queries with TimeUUIDs
Timestamp Precision Control
Type Conversion Round-Trip
Best Practices
- Use prepared statements with functions: Better performance for repeated operations
- TimeUUID for time-series data: Provides both ordering and uniqueness
- Blob conversions for compatibility: Useful when interfacing with external systems
- Aggregate with GROUP BY: Combine aggregate functions with grouping for analytics
- minTimeuuid/maxTimeuuid for time ranges: Efficient time-based queries on TimeUUID columns
- currentTimestamp() vs now(): Use
currentTimestamp()for TIMESTAMP columns,now()for TIMEUUID columns
Function Compatibility Notes
- All TimeUUID functions are compatible with Apache Cassandra
- Blob conversion functions follow Cassandra’s binary encoding
- Aggregate functions support standard CQL syntax
- Timestamp functions support both millisecond and microsecond precision (configured via flags)

