Search code examples
cassandratimeuuid

Cassandra limit clause for timestamp(timeuuid)


I have a cassandra table structure as follows

create table demo (user_id text , comment_id text , timestamp timeuuid , PRIMARY KEY (user_id , comment_id , timestamp))

Now in the UI I want pagination such that on the click of next button , I should get the value from 10 to 20 then 20 to 30 and so on.

I know we cant initiate a query in cassandra as

select * from demo limit 10,20 

So if I create a query as

select * from demo where timestamp = 'sometimestampvalue' limit 10;

This will give 10 values from 'sometimestampvalue' till next 10 values.

Then store the last row timestamp value in a variable (say X) and then initiate the next query as

select * from demo where timestamp = 'X' limit 10;

And so On, will this work ? or something better can be done as I'm ready to change the structure of table also with counter columns added as basically I should be able to do pagination based on any column.


Solution

  • See this answer: Cassandra Limit 10,20 clause

    Basically you will have to handle it in your app code. Your suggestion looks like it will work, with a little tweaking.