CQL for Cassandra 2.x

uuid and Timeuuid functions

Cassandra 2.0.7 and later includes the uuid() function. This function takes no parameters and generates a random Type 4 UUID suitable for use in INSERT or SET setatments.

Several Timeuuid functions are designed for use with the timeuuid type:

  • dateOf()

    Used in a SELECT clause, this function extracts the timestamp of a timeuuid column in a resultset. This function returns the extracted timestamp as a date. Use unixTimestampOf() to get a raw timestamp.

  • now()

    Generates a new unique timeuuid in milliseconds when the statement is executed. The timestamp portion of the timeuuid conforms to the UTC (Universal Time) standard. This method is useful for inserting values. The value returned by now() is guaranteed to be unique.

  • minTimeuuid() and maxTimeuuid()
    Returns a UUID-like result given a conditional time component as an argument. For example:
    SELECT * FROM myTable
       WHERE t > maxTimeuuid('2013-01-01 00:05+0000')
       AND t < minTimeuuid('2013-02-02 10:00+0000')
  • unixTimestampOf()

    Used in a SELECT clause, this functions extracts the timestamp in milliseconds of a timeuuid column in a resultset. Returns the value as a raw, 64-bit integer timestamp.

The min/maxTimeuuid example selects all rows where the timeuuid column, t, is strictly later than 2013-01-01 00:05+0000 but strictly earlier than 2013-02-02 10:00+0000. The t >= maxTimeuuid('2013-01-01 00:05+0000') does not select a timeuuid generated exactly at 2013-01-01 00:05+0000 and is essentially equivalent to t > maxTimeuuid('2013-01-01 00:05+0000').

The values returned by minTimeuuid and maxTimeuuid functions are not true UUIDs in that the values do not conform to the Time-Based UUID generation process specified by the RFC 4122. The results of these functions are deterministic, unlike the now function.

Show/hide