Anil
Anil

Reputation: 1488

Cassandra time stamp returns 0 rows

I created table column datatype as timestamp while storing it stores the default timestamp format yyyy-mm-dd HH:mm:ssZbut when try to select based on timestamp it doesn't return record.

CREATE TABLE TEST
(
  TS timestamp,
  VALUE text,
  EMAILID text,
  PRIMARY KEY (TS,VALUE)
);

INSERT INTO TEST(TS,VALUE,EMAILID) VALUES('1418026180922','sometext','email@');
SELECT * FROM TEST WHERE TS='2014-12-08 00:38:10-0800'  ALLOW FILTERING;

THIS Query returns 0 rows? Why it returns like that am i doing something wrong?

It works for below query:

SELECT * FROM TEST WHERE TS='1418026180922'  ALLOW FILTERING;

Upvotes: 0

Views: 152

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279890

Your query

SELECT * FROM TEST WHERE TS='2014-12-08 00:38:10-0800'  ALLOW FILTERING;

discards (or rather ignores) the millisecond part of the timestamp you use to insert the row

1418026180922 
//       ^^^^

And so the dates aren't equal.

If you had instead inserted

INSERT INTO TEST(TS,VALUE,EMAILID) VALUES('14180261800000','sometext','email@');

you could retrieve it with

select * from test where ts='2014-12-08 00:09:40-0800'; // note that I've fixed it from your '2014-12-08 00:38:10-0800'

Upvotes: 4

Related Questions