I have a CQL table defined like this:
CREATE table primary_key_only(
row_key varchar,
clustered_key varchar,
primary key(row_key, clustered_key)
)
Assuming I insert values like this:
INSERT INTO primary_key_only (row_key, clustered_key) VALUES ('FACE', 'D00D') USING TTL 86400;
How would I go about retrieving the TTL for the inserted data? Normally, if there was a CQL column that wasn't part of the primary key, then I could use a statement like:
SELECT ttl(<column_name>) FROM table WHERE row_key='key';
But since there are only primary key columns, functions like ttl
and writetime
won't work. How can I obtain the TTL, beyond adding an additional "dummy" column to the table that is not part of the primary key?
The primary key consists of only the partition key in this case. Data stored with a simple primary key will be fast to insert and retrieve if many values for the column can distribute the partitions across many nodes. Often, your first venture into using Cassandra involves tables with simple primary keys.
Setting a TTL for a specific columnUse CQL to set the TTL. To change the TTL of a specific column, you must re-insert the data with a new TTL. Cassandra upserts the column with the new TTL. To remove TTL from a column, set TTL to zero.
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.
Just for the sake of any future visitors, as of 2.2 this is still not possible without adding a dummy column.
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