Search code examples
cassandracql3

CQL: Bad Request: Missing CLUSTERING ORDER for column


What is the problem with this CQL query

cqlsh> create table citybizz.notifications(
   ...      userId varchar,
   ...      notifId UUID,
   ...      notification varchar,
   ...      time bigint,read boolean,
   ...      primary key (userId, notifId,time)
   ... ) with clustering order by (time desc);

It throws Bad Request: Missing CLUSTERING ORDER for column notifid. I am using cassandra 1.2.2


Solution

  • You need to specify the order for notifId too:

    create table citybizz.notifications(
        userId varchar,
        notifId UUID,
        notification varchar,
        time bigint,read boolean,
        primary key (userId, notifId,time)
    ) with clustering order by (notifId asc, time desc);
    

    Cassandra doesn't assume default ordering (asc) for the other clustering keys so you need to specify it.