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;
Use time-to-live (TTL) to expire data in a column or table. Expiring data with TTL example. Use the INSERT and UPDATE commands for setting the expire time (TTL) for data in a column. Inserting data using COPY and a CSV file. Inserting data with the cqlsh command COPY from a CSV file is common for testing queries.
In Cassandra Both the INSERT and UPDATE commands support setting a time for data in a column to expire. It is used to set the time limit for a specific period of time. By USING TTL clause we can set the TTL value at the time of insertion. We can use TTL function to get the time remaining for a specific selected query.
A SELECT expression using COUNT(*) returns the number of rows that matched the query. Alternatively, you can use COUNT(1) to get the same result.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With