Wednesday, 12 February 2020

Cassandra: Check a column ttl in cassandra

Syntax
SELECT TTL(columnName) FROM TABLE_NAME;

Sample CQL console log is given below.

cqlsh> CREATE keyspace cassandratutorial WITH REPLICATION = 
   ... { 
   ... 'class' : 'SimpleStrategy', 
   ... 'replication_factor' : 1 
   ... };
cqlsh> 
cqlsh> CREATE TABLE IF NOT EXISTS cassandratutorial.employee (
   ...   id INT PRIMARY KEY, 
   ...   firstName VARCHAR,
   ...   lastName VARCHAR,
   ...   age int,
   ... ) WITH comment = 'Table to store Employee information';
cqlsh> 
cqlsh> INSERT INTO cassandratutorial.employee JSON '{"id" : 1, "firstName" : "Krishna", "lastName" : "Gurram", "age" : 30}' USING TTL 300;
cqlsh>   
cqlsh> SELECT TTL(firstname) FROM cassandratutorial.employee WHERE id=1;

 ttl(firstname)
----------------
            228

(1 rows)
cqlsh>
cqlsh> UPDATE cassandratutorial.employee USING TTL 3600 SET firstname='RAMA' WHERE id=1;
cqlsh> 
cqlsh> SELECT TTL(firstname) FROM cassandratutorial.employee WHERE id=1;

 ttl(firstname)
----------------
           3597

(1 rows)
cqlsh> SELECT * FROM cassandratutorial.employee;

 id | age | firstname | lastname
----+-----+-----------+----------
  1 |  30 |      RAMA |   Gurram

(1 rows)
cqlsh> SELECT TTL(firstname) FROM cassandratutorial.employee WHERE id=1;

 ttl(firstname)
----------------
           3485

(1 rows)




Previous                                                    Next                                                    Home

No comments:

Post a Comment