我有这张桌子
user_authentication_token (
token_id uuid,
user_id uuid,
email text,
expiration_time timestamp,
is_sign_up boolean,
PRIMARY KEY ((token_id, user_id, email, expiration_time))
我在表中有此数据
token_id | user_id | email | expiration_time | is_sign_up
--------------------------------------+--------------------------------------+-------------------------+---------------------------------+------------
98b0456a-05b2-4aca-a6c7-6a1f382e19aa | b284d51d-efbb-4204-b342-a2486029a5c5 | manu.chadha@hotmail.com | 2018-09-01 09:40:59.634000+0000 | True
但是我无法查询它。
select * from user_authentication_token where token_id=98b0456a-05b2-4aca-a6c7-6a1f382e19aa and user_id=b284d51d-efbb-4204-b342-a2486029a5c5 and email='manu.chadha@hotmail.com' and expiration_time='2018-09-01 09:40:59.634000+0000';
错误-InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to coerce '2018-09-01 09:40:59.634000+0000' to a formatted date (long)"
我在做什么错了?
我使用Cassandra Java Datastax
驱动程序和以下代码插入了行
def insertValues(tableName:String, model:UserToken):Insert = {
QueryBuilder.insertInto(tableName).value("token_id",model.tokenId)
.value("email",model.email)
.value("user_id",model.userId)
.value("expiration_time",model.expirationTime.getMillis())
.value("is_sign_up",model.isSignUp)
.ifNotExists(); }}
有趣的是,时间戳记存储为long
,但cqlsh
以可读格式显示。可能需要再次将其转换为long
,但是我该怎么做?
答案 0 :(得分:0)
您的时间戳不应超过毫秒:
select * from user_authentication_token
where token_id=98b0456a-05b2-4aca-a6c7-6a1f382e19aa
and user_id=b284d51d-efbb-4204-b342-a2486029a5c5
and email='manu.chadha@hotmail.com'
and expiration_time='2018-09-01 09:40:59.634+0000'; // removed extra precision
更新:添加了以下Manu Chadha发现的时区偏移。