Friday 21 February 2020

Cassandra: String data types

Below table summarizes string data types supported in Cassandra.
Data Type
Description
ascii
ASCII character string
varchar
UTF8 encoded string
text
UTF8 encoded string. It is an alias for varchar.

Example
CREATE TABLE IF NOT EXISTS cassandratutorial.employee (
  id INT PRIMARY KEY, 
  first_name VARCHAR,
  description BLOB,
  male BOOLEAN,
  salary DOUBLE,
  ip_address inet,
  date_of_birth date,
  joining_time timestamp,
  unique_id uuid
);

INSERT INTO cassandratutorial.employee (id, first_name, description, male, salary, ip_address, date_of_birth, joining_time, unique_id) VALUES (1, 'Krishna', textAsBlob('I am Krishna, I am intrested in blogging, trekking'), true, 12345.67, '192.168.2.3', '1985-05-24', 1555494268, uuid());

cqlsh> CREATE KEYSPACE cassandratutorial WITH REPLICATION = 
   ... { 
   ...   'class' : 'SimpleStrategy', 
   ...   'replication_factor' : 1 
   ... };
cqlsh> 
cqlsh> CREATE TABLE IF NOT EXISTS cassandratutorial.employee (
   ...   id INT PRIMARY KEY, 
   ...   first_name VARCHAR,
   ...   description BLOB,
   ...   male BOOLEAN,
   ...   salary DOUBLE,
   ...   ip_address inet,
   ...   date_of_birth date,
   ...   joining_time timestamp,
   ...   unique_id uuid
   ... );
cqlsh> 
cqlsh> INSERT INTO cassandratutorial.employee (id, first_name, description, male, salary, ip_address, date_of_birth, joining_time, unique_id) VALUES (1, 'Krishna', textAsBlob('I am Krishna, I am intrested in blogging, trekking'), true, 12345.67, '192.168.2.3', '1985-05-24', 1555494268, uuid());
cqlsh> 
cqlsh> SELECT * FROM cassandratutorial.employee;

 id | date_of_birth | description                                                                                            | first_name | ip_address  | joining_time                    | male | salary   | unique_id
----+---------------+--------------------------------------------------------------------------------------------------------+------------+-------------+---------------------------------+------+----------+--------------------------------------
  1 |    1985-05-24 | 0x4920616d204b726973686e612c204920616d20696e7472657374656420696e20626c6f6767696e672c207472656b6b696e67 |    Krishna | 192.168.2.3 | 1970-01-19 00:04:54.268000+0000 | True | 12345.67 | bba0d1c0-b4c1-4e14-b36e-8ac2d2519bd3

(1 rows)
cqlsh>



Previous                                                    Next                                                    Home

No comments:

Post a Comment