如何在cassandra CQL 3命令行中自动生成uuid [英] How to auto generate uuid in cassandra CQL 3 command line

查看:1627
本文介绍了如何在cassandra CQL 3命令行中自动生成uuid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是学习cassandra,是有办法使用CQL插入一个UUID,即

 创建表的东西(uid uuid primary key,name varchar); 
insert into stuff(name)values('my name'); // failed
insert into stuff(uid,name)values(1,'my name'); // failed

您可以执行

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


解决方案

可以使用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.

这篇关于如何在cassandra CQL 3命令行中自动生成uuid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆