Create Cassandra table using cql3 with default TTL

Ziklag picture Ziklag · May 23, 2014 · Viewed 15.3k times · Source

Is it possible to create a table that has a default TTL for all rows that are inserted into it, or do you have to always remember to set the TTL when you do an insert/update?

Cant see anything on this in the documentation:

http://www.datastax.com/documentation/cql/3.0/cql/cql_reference/create_table_r.html

Answer

reggoodwin picture reggoodwin · May 23, 2014

Yes it is possible to set TTL for the entire column family.

CREATE TABLE test_table (
    # your table definition #
) WITH default_time_to_live = 10;

Inserted rows then disappear after 10 seconds.

I believe the work was done for it here:

https://issues.apache.org/jira/browse/CASSANDRA-3974

Here's a docs reference sent by Patrick McFadin of DataStax (@PatrickMcFadin):

http://docs.datastax.com/en/cql/3.1/cql/cql_reference/tabProp.html

Cheers,