Float Data Type in Cassandra Query Language - Cassandra / CQL Tutorial

Float Data Type in Cassandra Query Language ( CQL)

Float data type in Cassandra is used to save float and integer values.  Couple of things to note, The decimal number should not be starting with decimal , it should be starting with 0. Let's say you want to save .45, if you try to insert , you will be get below error. To Insert .45, start with 0.45 ( Zero dot 45).
SyntaxException: line 1:41 no viable alternative at input '.' (...(id,FloatValue) values(4,[.]...)

If you will insert more than 38 digits, it will show you as Infinity value in table.
Le't create sample table in CQL with data type float and insert some sample data.
CQLSH:techbrotherstutorials>CREATE TABLE tbs 
             ( 
                          id INT PRIMARY KEY, 
                          floatvalue FLOAT 
             );
Insert sample data into tbs table which has column floatvalue as float data type.

CQLSH:techbrotherstutorials>INSERT INTO tbs
            (
                        id,
                        floatvalue
            )
            VALUES
            (
                        1,100
            );INSERT INTO tbs
            (
                        id,
                        floatvalue
            )
            VALUES
            (
                        2,
                        400.56
            );INSERT INTO tbs
            (
                        id,
                        floatvalue
            )
            VALUES
            (
                        3,
                        3333333333333333333333333333444444444456
            );INSERT INTO tbs
            (
                        id,
                        floatvalue
            )
            VALUES
            (
                        4,
                        0.45
            );INSERT INTO tbs
            (
                        id,
                        floatvalue
            )
            VALUES
            (
                        5,
                        3333333333333333333333.9999444444444456
            );

Check the data in tbs table by using Select query in CQL
CQLSH:techbrotherstutorials>SELECT * 
FROM   tbs; 

1 comment: