这是我在论坛上的第一个查询,因此如果我的理解有误,请更正。
我正在从DS201执行练习“应用程序驱动程序连接”。
表格如下:
cqlsh:killrvideo> SELECT * FROM videos_by_tag ;
tag | added_date | video_id | title
-----------+---------------------------------+--------------------------------------+------------------------------
datastax | 2013-10-16 00:00:00.000000+0000 | 4845ed97-14bd-11e5-8a40-8338255b7e33 | DataStax Studio
现在,我想按照实验室执行一项任务“将新视频插入数据库的Python代码”。
我尝试了这段代码并出现错误:
>>> session.execute(
... "INSERT INTO videos_by_tag (tag, added_date, video_id, title)" +
... "VALUES ('cassandra', '2013-01-10', uuid(), 'Cassandra Is My Friend')")
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "cassandra/cluster.py", line 2618, in cassandra.cluster.Session.execute
File "cassandra/cluster.py", line 4877, in cassandra.cluster.ResponseFuture.result
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Type error: cannot assign result of function system.uuid (type uuid) to video_id (type timeuuid)"
>>>
我在下面尝试了但失败了:
错误:
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Unknown function uuids.timebased called"
错误:
cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:109 no viable alternative at input '.' (...)VALUES ('cassandra', '2013-01-10', [cassandra].util...)">
暂时我已经将值硬编码了。
session.execute(
... "INSERT INTO videos_by_tag (tag, added_date, video_id, title)" +
... "VALUES ('cassandra', '2013-01-10', 245e8024-14bd-11e5-9743-8238357b7e32, 'Cassandra Is My Friend')")
DB成功:
cassandra | 2013-01-10 00:00:00.000000+0000 | 245e8024-14bd-11e5-9743-8238357b7e32 | Cassandra Is My Friend
但是我想知道吗?
您是正确的,因为对该uuid()
函数的调用是您的问题:
INSERT INTO videos_by_tag (tag,added_date,video_id,title)
VALUES ('cassandra', '2013-01-10', uuid(), 'Cassandra Is My Friend');
该uuid()
函数生成4型UUID,而该video_id
列定义为1型UUID(又名a TIMEUUID
)。
而是调用now()
函数以获取TIMEUUID
:
INSERT INTO videos_by_tag (tag,added_date,video_id,title)
VALUES ('cassandra', '2013-01-10', now(), 'Cassandra Is My Friend');
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句