17

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

Martin Schröder
  • 4,176
  • 7
  • 47
  • 81
Ziklag
  • 251
  • 1
  • 2
  • 6
  • Ziklag, the information about this is actually in a different page, the "table attributes" page as default_time_to_live (see my link in answer below). Cheers. – reggoodwin May 23 '14 at 20:04

3 Answers3

32

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,

Aaron
  • 55,518
  • 11
  • 116
  • 132
reggoodwin
  • 1,514
  • 13
  • 14
  • Datastax link is 404. – Sam Berry Sep 01 '15 at 14:07
  • 1
    Question about this answer : In the doc , it says :You can effectively delete any column TTLs in a table by setting the default_time_to_live to zero. Does it means it is deleting a column instead of a row ? – Seng Zhe May 26 '17 at 03:24
0

From Cassandra doc :

You can set a default TTL for an entire table by setting the table's default_time_to_live property. If you try to set a TTL for a specific column that is longer than the time defined by the table TTL, Apache Cassandra™ returns an error.

See: https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_expire_t.html

And here for general purposes about TTL: https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_expire_c.html

Marouane Gazanayi
  • 5,063
  • 6
  • 39
  • 58
0

You can set TTL either on table or during INSERT/UPDATE. When you will create a table you can define or set default_time_to_live or you can update later once table created with default TTL value. if you want to set a row level TTL you can set while inserting the row or updating any row. Below is good point you van refer regarding this:- https://www.geeksforgeeks.org/time-to-live-ttl-for-a-column-in-cassandra/ and https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/cqlCreateTable.html#tabProp__cqlTableDefaultTTL

LetsNoSQL
  • 1,478
  • 1
  • 11
  • 23