Gaurav Gupta
Gaurav Gupta

Reputation: 4691

Cassandra :[Invalid query] message="PRIMARY KEY column "lng" cannot be restricted

I am getting an error while executing following query in cqlsh

Query

SELECT * FROM ragchews.disc_location WHERE country_code = 12 AND lat > 100.00 and lat < 120.00 and lng > 50 and lng < 100 allow filtering;

Table

CREATE TABLE ragchews.disc_location (
    country_code int,
    lat float,
    lng float,
    uid text,
    PRIMARY KEY (country_code, lat, lng, uid)
);

Error:

code=2200 [Invalid query] message="PRIMARY KEY column "lng" cannot be restricted (preceding column "ColumnDefinition{name=lat, type=org.apache.cassandra.db.marshal.FloatType, kind=CLUSTERING_COLUMN, componentIndex=0, indexName=null, indexType=null}" is either not restricted or by a non-EQ relation)"

Cassandra version

[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]

Edit 1

Following query works fine for me

SELECT * FROM ragchews.disc_location WHERE country_code=91 and lat > 32 and lat < 100  allow filtering;

That looks like something is wrong with column lng.

Upvotes: 1

Views: 2679

Answers (2)

Jaya Ananthram
Jaya Ananthram

Reputation: 3463

You cannot have such query. You can add > or < for your last part of your where clause clustering key, provided = for the preceding keys. For example the following query will work fine,

SELECT * FROM ragchews.disc_location WHERE country_code = 12 AND lat = 100.00 and lng > 50 and lng < 100;

or even the following will work,

SELECT * FROM ragchews.disc_location WHERE country_code = 12 AND lat = 100.00 and lng = 50 and uid > '500' and uid  < '1000'

But two where clause having > or < condition will wont work.

Upvotes: 3

codejitsu
codejitsu

Reputation: 3182

If I understand this right, you have to use the '=' operator for all composite key columns except the last one. The last one (in your case lng) can be restricted with '<' or '>'.

Here the link: http://www.datastax.com/dev/blog/whats-new-in-cql-3-0

Upvotes: 2

Related Questions