BigInt Data Type in Cassandra Query Language ( CQL) - Cassandra / CQL Tutorial

BigInt Data Type in Cassandra Query Language ( CQL)

BigInt in Cassandra Query Language ( CQL) takes 8 bytes storage to save the value. The range for BigInt is -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)
Let's create a table with BigInt data type by using Cassandra Query Language ( CQL). 
CQLSH:techbrotherstutorials>CREATE TABLE tbs 
  ( 
     id          INT PRIMARY KEY, 
     bigintvalue BIGINT 
  ) ;
Let's insert some big values and test, I am going to insert couple of values in the range and couple of values out of range and see what message we get from Cassandra when run our statement.
CQLSH:techbrotherstutorials> INSERT INTO tbs 
            (id, 
             bigintvalue) 
VALUES      (1, 
             -10000000); 

INSERT INTO tbs 
            (id, 
             bigintvalue) 
VALUES      (2, 
             200000); 

INSERT INTO tbs 
            (id, 
             bigintvalue) 
VALUES      (3, 
             -9223372036854775999); 

INSERT INTO tbs 
            (id, 
             bigintvalue) 
VALUES      (4, 
             9223372036854775999); 

Noticed that first two values  -10000000 and 200000 are in range. Last two values -9223372036854775999 and 9223372036854775999 are out of range. When I tried to insert, I got below error.
InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to make long from '-9223372036854775999'"
Let's run Select query on table to check the data. 
CQLSH:techbrotherstutorials>SELECT * 
FROM   tbs;

1 comment: