【问题标题】:Inserting timestamp into Cassandra将时间戳插入 Cassandra
【发布时间】:2017-03-06 10:52:21
【问题描述】:

我有一个如下创建的表:

CREATE TABLE my_table (
  date text,
  id text,
  time timestamp,
  value text,
  PRIMARY KEY (id));

CREATE INDEX recordings_date_ci ON recordings (date);

我可以使用以下节点代码向表中简单地添加一个新行:

const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['localhost'], keyspace: 'my_keyspace'});

const query = 'INSERT INTO my_table (date, id, time, url) VALUES (?, ?, ?, ?)';
client.execute(query, ['20160901', '0000000000', '2016-09-01 00:00:00+0000', 'random url'], function(err, result) {
  if (err){
    console.log(err);
  }
  console.log('Insert row ended:' + result);
});

但是,我收到以下错误:

'错误:日期 (24) 的预期长度为 8 或 0 字节

当我将时间戳更改为 epoc 时间时:

client.execute(query, ['20160901', '0000000000', 1472688000, 'random url']

我得到: d

溢出错误:标准化的天数太大而无法放入 C int 中

我可以通过 cqlsh 插入新行,所以我可能在 node.js 驱动程序中遗漏了一些东西。

有什么想法吗?

谢谢

【问题讨论】:

    标签: node.js cassandra cassandra-node-driver


    【解决方案1】:

    如果你有一个字符串2016-09-01 00:00:00+0000,请改用new Date('2016-09-01 00:00:00+0000')

    【讨论】:

    • 完美。谢谢。我应该得到那个:-)
    猜你喜欢
    • 2018-10-06
    • 1970-01-01
    • 2013-05-08
    • 2014-05-10
    • 2015-08-24
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多