且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在cassandra CQL 3命令行中自动生成uuid

更新时间:2023-02-21 09:45:14

可以使用time uuids(type 1 UUID)using例如

  insert into stuff(uid,name)values(now(),'my name') 

要执行此操作,您需要将uid的类型更改为timeuuid。



虽然


$ b strong> UPDATE:此答案与Cassandra的旧版本有关。对于较新版本,请参阅下文。

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');

You can with time uuids (type 1 UUID) using the now() function e.g.

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

To do this, you will need to change the type of uid to timeuuid.

There isn't such a function for type 4 UUIDs though.


UPDATE: This answer pertains to older versions of Cassandra. For newer versions, see below.