Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQL check if record exists

Tags:

cassandra

cql

I'm on my path to learning Cassandra, and the differences in CQL and SQL, but I'm noticing the absence of a way to check to see if a record exists with Cassandra. Currently, the best way that I have is to use

SELECT primary_keys FROM TABLE WHERE primary_keys = blah, 

and checking to see if the results set is empty. Is there a better way to do this, or do I have the right idea for now?

like image 809
Jim Pedid Avatar asked Dec 24 '15 15:12

Jim Pedid


1 Answers

Using count will make it traverse all the matching rows just to be able to count them. But you only need to check one, so just limit and return whatever. Then interpret the presence of the result as true and absence - as false. E.g.,

SELECT primary_keys FROM TABLE WHERE primary_keys = blah LIMIT 1
like image 197
Nikita Volkov Avatar answered Sep 21 '22 18:09

Nikita Volkov