我有一个表,其中有一列类型为timestamp的表,当我插入一个值时,Scylla会将其另存3个零。
根据Scylla文档(https://docs.scylladb.com/getting-started/types/#timestamps):
可以将时间戳记的值用作整数,也可以使用表示ISO 8601日期的字符串在CQL中输入时间戳记。例如,以下所有值都是2011年3月2日格林尼治标准时间04:05:00的有效时间戳值:
- 1299038700000
- '2011-02-03 04:05 + 0000'
- '2011-02-03 04:05:00 + 0000'
- '2011-02-03 04:05:00.000 + 0000'
- '2011-02-03T04:05 + 0000'
- '2011-02-03T04:05:00 + 0000'
- '2011-02-03T04:05:00.000 + 0000'
所以当我创建一个表时,例如:
CREATE TABLE callers (phone text, timestamp timestamp, callID text, PRIMARY KEY(phone, timestamp));
并在其中插入值:
INSERT INTO callers (phone, timestamp, callID) VALUES ('6978311845', 1299038700000, '123');
INSERT INTO callers (phone, timestamp, callID) VALUES ('6978311846', '2011-02-03 04:05+0000', '456');
INSERT INTO callers (phone, timestamp, callID) VALUES ('6978311847', '2011-02-03 04:05:00.000+0000', '789');
SELECT * FROM callers;
将在点后多显示3个零的所有时间戳:
phone | timestamp | callid
------------+---------------------------------+--------
6978311847 | 2011-02-03 04:05:00.000000+0000 | 789
6978311845 | 2011-03-02 04:05:00.000000+0000 | 123
6978311846 | 2011-02-03 04:05:00.000000+0000 | 456
因此,当我尝试删除一行时:
DELETE FROM callers WHERE phone = '6978311845' AND timestamp = '2011-03-02 04:05:00.000000+0000';
发生错误:
InvalidRequest: Error from server: code=2200 [Invalid query] message="marshaling error: unable to parse date '2011-03-02 04:05:00.000000+0000': marshaling error: Milliseconds length exceeds expected (6)"
如何在不出现此错误的情况下存储时间戳?
答案 0 :(得分:3)
您有hr:min:sec.millisec-> Millisec最高可以达到999/1000,因此本质上这就是错误所在。
您所做的3 INSERT
语句在语法上是正确的。
DELETE
语句的格式应与INSERT
相同:
AND timestamp = '2011-03-02 04:05:00.00+0000'
AND timestamp = '2011-03-02 04:05:00.000+0000'
AND timestamp = '2011-03-02 04:05:00+0000'
AND timestamp = '2011-03-02 04:05:00'
表中出现的其他000
只是一个显示问题。