Search code examples
cassandracqlcql3

Check a rows TTL in cassandra?


I have a table/column family which I am inserting rows that expire after a certain amount of time. Is it possible to then query the table to check which rows are going to expire soon (for diagnostic purposes, ie something like this:

select subject, ?ttl? from discussions;

Solution

  • You can do

    select subject, TTL(subject) from discussions;
    

    to return the remaining TTL in seconds for subject.

    E.g.

    > insert into discussions (uid, subject) VALUES (now(), 'hello') using ttl 100;
    > select subject, TTL(subject) from discussions;
    
     subject | ttl(subject)
    ---------+--------------
       hello |           84
    

    since I waited 16 seconds before running the select.