How to auto generate uuid in cassandra CQL 3 command line

Jay picture Jay · Jul 30, 2013 · Viewed 64.7k times · Source

Just learning cassandra, is there a way to insert a UUID using CQL, ie

create table stuff (uid uuid primary key, name varchar);
insert into stuff (name) values('my name'); // fails
insert into stuff (uid, name) values(1, 'my name'); // fails

Can you do something like

insert into stuff (uid, name) values(nextuid(), 'my name');

Answer

lumi picture lumi · Aug 15, 2014

As of Cassandra 2.0.7 you can just use uuid(), which generates a random type 4 UUID:

INSERT INTO users(uid, name) VALUES(uuid(), 'my name');