Latest Post

Wednesday, 21 December 2016

What is Tuples Data Type in Cassandra Database

Tuples Data Type
CQL support tuples and tuple types. Tuple is type where the elements can be of different types.

Syntax: - Tuple types and tuple literals are defined by:
tuple_type    ::=  TUPLE '<' cql_type ( ',' cql_type )* '>'
tuple_literal ::=  '(' term ( ',' term )* ')'


Example:-
cqlsh:payroll> CREATE TABLE durations (
           ...     id int PRIMARY KEY,
           ...     event text,
           ...     duration tuple<int, text>,
           ... );
cqlsh:payroll> Select * from durations;

 id | duration | event
----+----------+-------

(0 rows)
cqlsh:payroll> INSERT INTO durations (id, event, duration) VALUES (1,'event1', (3, 'hours'));
cqlsh:payroll> INSERT INTO durations (id, event, duration) VALUES (2,'event2', (2, 'hours'));
cqlsh:payroll> INSERT INTO durations (id, event, duration) VALUES (3,'event3', (4, 'hours'));
cqlsh:payroll> INSERT INTO durations (id, event, duration) VALUES (4,'event4', (3, 'hours'));

cqlsh:payroll> select * from durations;

 id | duration     | event
----+--------------+--------
  1 | (3, 'hours') | event1
  2 | (2, 'hours') | event2
  4 | (3, 'hours') | event4
  3 | (4, 'hours') | event3

(4 rows)

Government Jobs