Friday 21 February 2020

Cassandra: How to generate uuid?

'uuid()' function generates an uuid of type 4.

Example
INSERT INTO cassandratutorial.employee(id, first_name) VALUES (uuid(), 'Krishna');

CQL code snippet
CREATE KEYSPACE cassandratutorial WITH REPLICATION = 
{ 
  'class' : 'SimpleStrategy', 
  'replication_factor' : 1 
};

CREATE TABLE IF NOT EXISTS cassandratutorial.employee (
  id uuid PRIMARY KEY, 
  first_name VARCHAR
);

INSERT INTO cassandratutorial.employee(id, first_name) VALUES (uuid(), 'Krishna');

Cqlsh console output
cqlsh> CREATE KEYSPACE cassandratutorial WITH REPLICATION = 
   ... { 
   ...   'class' : 'SimpleStrategy', 
   ...   'replication_factor' : 1 
   ... };
cqlsh> 
cqlsh> CREATE TABLE IF NOT EXISTS cassandratutorial.employee (
   ...   id uuid PRIMARY KEY, 
   ...   first_name VARCHAR
   ... );
cqlsh> 
cqlsh> INSERT INTO cassandratutorial.employee(id, first_name) VALUES (uuid(), 'Krishna');
cqlsh> 
cqlsh> SELECT * FROM cassandratutorial.employee;

 id                                   | first_name
--------------------------------------+------------
 5987fd93-1783-4a14-a17a-5fc4fb191c2c |    Krishna

(1 rows)




Previous                                                    Next                                                    Home

No comments:

Post a Comment