Gobi
Gobi

Reputation: 41

Apply TTL in column level

Want to know, how to apply TTL in column level.

below query set the TTL at record level

  INSERT INTO excelsior.clicks (
  userid, url, date, name)
  VALUES 
    (
    3715e600-2eb0-11e2-81c1-0800200c9a66,
   'http://apache.org',
   '2013-10-09', 'Mary'
     )
    USING TTL 86400;

whereas my requirement is setting TTL for a particular column. Is there any way to achieve this

Upvotes: 1

Views: 631

Answers (1)

Jeff Jirsa
Jeff Jirsa

Reputation: 4426

You can do an INSERT with partial data:

cqlsh> create KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
cqlsh> use test;
cqlsh:test> create table test(userid uuid, url text, date text, name text, primary key(userid));
cqlsh:test> 
cqlsh:test> insert into test(userid, url, date, name) VALUES 
        ...     (
        ...     3715e600-2eb0-11e2-81c1-0800200c9a66,
        ...    'http://apache.org',
        ...    '2013-10-09', 'Mary'
        ...      )
        ...     USING TTL 86400;
cqlsh:test> 
cqlsh:test> select userid, url, TTL(url), date, TTL(date), name, TTL(name) from test;

 userid                               | url               | ttl(url) | date       | ttl(date) | name | ttl(name)
--------------------------------------+-------------------+----------+------------+-----------+------+-----------
 3715e600-2eb0-11e2-81c1-0800200c9a66 | http://apache.org |    86342 | 2013-10-09 |     86342 | Mary |     86342

(1 rows)    
cqlsh:test> insert into test(userid, url ) VALUES (3715e600-2eb0-11e2-81c1-0800200c9a66,    'http://apache.org'   ) USING TTL 864000; 
cqlsh:test> 
cqlsh:test> select userid, url, TTL(url), date, TTL(date), name, TTL(name) from test;

 userid                               | url               | ttl(url) | date       | ttl(date) | name | ttl(name)
--------------------------------------+-------------------+----------+------------+-----------+------+-----------
 3715e600-2eb0-11e2-81c1-0800200c9a66 | http://apache.org |   863992 | 2013-10-09 |     86109 | Mary |     86109

(1 rows)
cqlsh:test> 

If you do an insert statement per column, you can set a TTL on each column individually.

Upvotes: 1

Related Questions