liveBook · Manning

Now

As explained in ScyllaDB in Action

The now() function is a ScyllaDB function that generates a TIMEUUID from the current time and the hardware MAC address.

now() generates a TIMEUUID from the current time and the hardware MAC address. Because TIMEUUID values encode timestamps, they can order records by creation time. section 4.4.1

Use now() when inserting a row whose primary key is a TIMEUUID. It avoids manually creating the identifier, but the application cannot know the generated key until it reads the row. section 4.4.1 section 6.1.1

Insert an author

An authors table can use a TIMEUUID primary key. Insert an author with `INSERT INTO authors(id, name) VALUES (now(), 'Alice Author');`. If the generated ID must be reused immediately, generate the TIMEUUID externally instead. section 6.1.1

cqlsh: types> INSERT INTO basic(text, uuid, timeuuid)
  VALUES ('uuids', uuid(), now());

Try now() alongside uuid() in cqlsh to compare a random UUID with a time-based UUID. section 4.4.1

ScyllaDB can convert the resulting TIMEUUID back into a readable timestamp with toTimestamp(timeuuid), making the encoded time visible in query results. section 4.4.1

How ScyllaDB in Action covers it

How deep it goes
Explains identifier construction, timestamp ordering, insertion syntax, and the consequence of not knowing generated keys immediately.
Examples
Demonstrates cqlsh insertion, author records, UUID comparison, and converting a TIMEUUID into a readable timestamp.
What it assumes
Assumes familiarity with CQL INSERT statements and primary keys while explaining UUID and TIMEUUID behavior directly.
What you can do after
Apply it via CQL to create TIMEUUID values during inserts and recognize when external generation is preferable.
How it connects
Connects TIMEUUID values with UUID generation, primary keys, timestamp extraction, and application-side identifier management.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.