16

Hi is there any way I can use != operator using CQL in Cassandra? I am trying to use a != operator on my columnfamily but when I try using that it says:

cqlsh:EPCContent> select * from "MediaCategoryGroup" where "MCategoryID"!=1;

I get this error:

Invalid syntax at line 1, char 55
  select * from "MediaCategoryGroup" where "MCategoryID"!=1;
                                                        ^
Aaron
  • 55,518
  • 11
  • 116
  • 132
Gargee Banerjee
  • 215
  • 1
  • 3
  • 9

2 Answers2

18

If you look at the Cassandra SELECT syntax, you will see that the WHERE clause must be "composed of relations on the columns that are part of the PRIMARY KEY and/or have a secondary index defined on them." Does your column conform to that specification?

Just for your information this is the full list of relation operators: '=' | '<' | '>' | '<=' | '>=' | '!=' | IN | CONTAINS | CONTAINS KEY.

Colin Strong
  • 118
  • 1
  • 9
emgsilva
  • 3,047
  • 1
  • 17
  • 16
  • But we can use "<" | ">" | "<=" | ">=" only if that field is a Primary key. – Gargee Banerjee Oct 15 '13 at 23:03
  • 1
    yes, in Cassandra you can only do that on primary key fields (also from composite keys) or "secondary indexes" and not all of them are possible all the times... – emgsilva Oct 15 '13 at 23:05
  • How would you do it to get all the rows where a specific field is not null? – David Torres Jun 13 '16 at 09:21
  • @DavidTorres I am not sure you will be able to do that directly on a Cassandra query. As mentioned you cannot use the "!=" operator (not sure if this has changed on recent versions of Cassandra). Furthermore, I believe the fields you can use in filtering/operators (part of primary key or composite key) all need to be different from null... So, most probably you need to perform a read of relevant elements and then do some other filtering on your application. – emgsilva Jun 15 '16 at 08:20
-3

Go with <> instead !=. It's working for me.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 22 '22 at 11:23