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

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

问题描述

刚学习cassandra,有没有办法用CQL插入UUID,即

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

你能做类似的事情吗

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

推荐答案

您可以使用 now() 函数 eg

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

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

使用 uid 或 timeuuid.它会生成一个保证唯一"的 UID 值,其中还包含时间戳,因此可以按时间排序.

Works with uid or timeuuid. It generates a "guaranteed unique" UID value, which also contains the timestamp so is sortable by time.

不过,对于类型 4 UUID 没有这样的功能.

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

更新:此说明适用于旧版本的 Cassandra.对于较新的版本,请参见下文.

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

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

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