List Data Type in Cassandra - Cassandra / CQL Tutorial

List Data Type in Cassandra

When you need to store list of elements such as list of textual, integer or other data types then you can use List Collection type. To use List collection type, first you have to declare List and then data type of elements e.g List<Text> or List<integer>
In below example, I am creating a table which has parent name, Children Column which is declared as List Collection of Text type and ChildrenAge as List of Integers.
CQLSH:techbrotherstutorials>CREATE TABLE tbs 
             ( 
                          id INT PRIMARY KEY, 
                          NAME TEXT, 
                          children LIST<text>, 
                          childrenage LIST<smallint> ;

Let's insert a record in table, for List Collection, you will be using [ element1, element2.....] 
CQLSH:techbrotherstutorials>INSERT INTO tbs 
            ( 
                        id, 
                        NAME, 
                        children, 
                        childrenage 
            ) 
            VALUES 
            ( 
                        1, 
                        'Aamir', 
                        ['najaf','rida'], 
                        [15,14] 
            );

Let's verify the data by using Select statement in CQL 
CQLSH:techbrotherstutorials>SELECT * 
FROM   tbs; 

1 comment: