2017-06-01 74 views
0

我是casandra的新手,我需要在表中插入下一个增量id 试图使用mysql的语法。如何从casandra trable获取下一个ID

INSERT INTO demo.log (id, transaction_type , transaction_time, transaction_data, session_id) VALUES (select max(id)+1 from demo.log ,'master' ,'2017-05-27 14:30:54.234' ,'1›6378925487955990›1›0›251›96544›/Date(1474519292176+0800)/›200›3›1›0' ,'789789d7f9-k97f8gh9f8f-001'); 

错误:

SyntaxException: line 1:117 no viable alternative at input 'select' (..., session_id) VALUES ([(]select...) 
+0

你不能在CQL中做子选择。而[集成函数中的内建函数](http://docs.datastax.com/en/cql/3.3/cql/cql_using/useQueryStdAggregate.html)只能对分区键进行操作。 – Ralf

回答

2

你不能做到这一点(子查询),毫无特色,以支持它,它也不会得到支持。你可以使用计数器或LWT这样的工作,但这是一个非常糟糕的主意。

我会建议你使用类型1或4 uuids的id(设置类型为timeuuid或uuid)。在分布式系统中,自动增加这样的东西非常昂贵且复杂。