CQL checks if a record exists

I am on my way to learning about Cassandra and the differences in CQL and SQL, but I notice there is no way to check if a record exists with Cassandra. Currently, the best way I have is to use

SELECT primary_keys FROM TABLE WHERE primary_keys = blah, 

and check if the result set is empty. Is there a better way to do this, or do I have the right idea?

+4
source share
3 answers

This is the usual way in Kassandra to check if a string exists. You might not want to return all primary keys if all you care about is if the string exists or not, so you can do this:

SELECT count(*) FROM TABLE WHERE primary_keys = blah, 

This will simply return 1 if the string exists, and 0 if it does not exist.

+7

count, , . , . true - false. .

SELECT primary_keys FROM TABLE WHERE primary_keys = blah LIMIT 1
+4

, 3 ( ) . , .

(, , ) , "Limit 1", .

There is a corresponding example: Best way to check for filtered strings in Cassandra? by user aggregate?

0
source

Source: https://habr.com/ru/post/1621635/


All Articles