Create Cassandra table using cql3 with default TTL
Asked Answered
T

3

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

Tiling answered 23/5, 2014 at 10:24 Comment(1)
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.Saboteur
S
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,

Saboteur answered 23/5, 2014 at 11:48 Comment(2)
Datastax link is 404.Colombi
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 ?Gabe
H
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

Havelock answered 9/3, 2018 at 13:40 Comment(0)
D
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

Dupont answered 18/4, 2020 at 5:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.