Reputation: 425
I have the following table:
CREATE TABLE records(
device_id text,
read_time timestamp,
data_row text,
PRIMARY KEY (device_id, read_time ))
WITH CLUSTERING ORDER BY (read_time DESC);
I want to get all the records starting with the one before a specific read_time. Is there a way to do that? I thought maybe having another field previous_read_time, but it will be hard to maintain since I sometime get out of order reads.
Upvotes: 0
Views: 334
Reputation: 1530
I don't think there's any CQL statement that does this (filter on a timestamp column PLUS the first record not matching the time filter). But depending on your exact case maybe something like the following would work for you?
For example I will find all records with read_time after 2020-05-14 00:00:01
plus the first one on-or-before 2020-05-14 00:00:01
:
2020-05-14 00:00:01
).SELECT * FROM records WHERE device_id=? AND read_time > '2020-05-14 00:00:01';
2020-05-14 00:00:01
.// Let's say you find records with the following times.
// The earliest (closest to the filter's time) is 2020-05-14 00:00:55
2020-05-14 00:00:55
2020-05-14 00:00:56
2020-05-14 00:30:55
2020-05-14 13:30:55
SELECT * FROM records WHERE device_id=? AND read_time < 2020-05-14 00:00:55 LIMIT 1;
Upvotes: 1