Loki
Loki

Reputation: 6261

What's wrong with this cassandra prepared statement call?

I'm using the datastax cassandra driver for python.

The portion of the code at issue is:

cql = "SELECT * FROM iptools.geo2ip WHERE geo_key = ? AND (( geohash >= ? AND geohash < ? ) OR ( geohash >= ? AND geohash < ? ));"
print cql
prepared = self.session.prepare(cql)

Results are:

SELECT * FROM iptools.geo2ip WHERE geo_key = ? AND (( geohash >= ? AND geohash < ? ) OR ( geohash >= ? AND geohash < ? ));
cassandra.protocol.SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:82 missing EOF at ')' (...? AND geohash < ? [)];)">

I'm not sure where the brackets around the parenthesis are coming from, and the prepare statement works as soon as I remove the parenthesis.

Ideas?

Upvotes: 1

Views: 1493

Answers (1)

Aaron
Aaron

Reputation: 57748

I'm pretty sure this is happening because CQL does not contain a definition for the OR keyword. One shortcut that has been used in place of OR, is IN:

SELECT * FROM geo2ip WHERE geo_key IN (?,?);

Although be forewarned that IN is known to not perform very well. However, I don't think that will help you much anyway, as it looks like you want to be able to do a range query on geohash. Depending on your PRIMARY KEY definition (for instance, with geo_key as the partition key and geohash as the clustering key), this (minus the complexOR` logic) should still work:

SELECT * FROM iptools.geo2ip WHERE geo_key = ? AND geohash >= ? AND geohash < ?;

Upvotes: 1

Related Questions