-5

How can i convert below SQL query to CQL query?

SELECT * FROM csv_report WHERE sensor_id=170268 AND create_day BETWEEN 20150401 AND 20150403;

also i trying different BETWEEN query:

SELECT * FROM csv_report WHERE sensor_id=170268 AND create_day >= 20150401 AND create_day <= 20150403;

But this query raised an error:

code=2200 [Invalid query] message="Only EQ and IN relation are supported on the partition key (unless you use the token() function)"

M.javid
  • 6,387
  • 3
  • 41
  • 56
  • Well for SQL Server at least, normally dates go in single quotes. So something like create_day BETWEEN '20150401' AND '20150403'. I don't think you can put in 00 for the day. – Stephan May 09 '15 at 08:11
  • Thanks @Stephan, but i work on available cassandra db, and i must get data from this type of db. – M.javid May 09 '15 at 09:39

1 Answers1

2

Try this

SELECT * 
FROM csv_report 
WHERE sensor_id=170268 
AND create_day IN (20150401, 20150402, 20150403);
Clément Prévost
  • 8,000
  • 2
  • 36
  • 51
  • The reason this is likely to work is that, based on the error, you (Mohsen) have both sensor_id and create_day as elements in the partition key portion of the primary key. When doing a SELECT, cassandra will hash the values of the partition key to determine which nodes hold the partitions, so using a range in the WHERE clause is unsupported. If you need to use ranges/inequality, you must use them on the clustering key portion of the primary key. – Jeff Jirsa May 10 '15 at 04:23