How to auto generate uuid in cassandra CQL 3 command line

后端 未结 4 1505
名媛妹妹
名媛妹妹 2020-12-25 11:14

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) valu         


        
4条回答
  •  星月不相逢
    2020-12-25 11:37

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

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

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

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


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

提交回复
热议问题