Lior Ohana Lior Ohana - 1 year ago 127
Node.js Question

Inserting timestamp into Cassandra

I have a table created as follows:

CREATE TABLE my_table (
date text,
id text,
time timestamp,
value text,

CREATE INDEX recordings_date_ci ON recordings (date);

I'm able to simply add a new row to the table using the following Node code:

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('Insert row ended:' + result);

However, I get the following error:

'Error: Expected 8 or 0 byte long for date (24)

When I change the timestamp to epoc time:

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

I get:

OverflowError: normalized days too large to fit in a C int

I'm able to insert new rows via cqlsh so I'm probably missing something with the node.js driver.

Any idea?


Answer Source

Where you have a string 2016-09-01 00:00:00+0000, instead use new Date('2016-09-01 00:00:00+0000').

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download