Search code examples
cassandracqlcassandra-2.0cql3cqlsh

Why do these CQL3 queries with where-clauses against a table (with a compound key) fail to return anything?


I get no rows back with any kind of CQL3 query with a where clause against this table:

CREATE TABLE mydata (
  key1 text,
  key2 int,
  key3 int,
  key4 int,
  statustime timestamp,
  status text,
  name text,
  PRIMARY KEY ((key1, key2, key3, key4), statustime, status)
);

Here is my sample data

cqlsh:testing> select * from mydata;

 key1      | key2          | key3         | key4         | statustime               | status     | name
-----------+---------------+--------------+--------------+--------------------------+------------+-------
     'xxx' |           100 |          100 |          100 | 1971-01-01 04:00:00-0800 |   'active' | 't1'
     'xxx' |           100 |          100 |          100 | 1972-01-01 04:00:00-0800 | 'disabled' | 't2'
     'xxx' |           100 |          100 |          100 | 1973-01-01 04:00:00-0800 |   'active' | 't2'
     'xxx' |           100 |          100 |          100 | 1974-01-01 04:00:00-0800 |   'active' | 't3'
     'yyy' |           300 |          300 |          300 | 1971-01-01 04:00:00-0800 |   'active' | 't1'
     'yyy' |           300 |          300 |          300 | 1972-01-01 04:00:00-0800 | 'disabled' | 't2' 
     'yyy' |           300 |          300 |          300 | 1973-01-01 04:00:00-0800 |   'active' | 't2' 
     'yyy' |           300 |          300 |          300 | 1974-01-01 04:00:00-0800 |   'active' | 't3' 
     'zzz' |           200 |          200 |          200 | 1971-01-01 04:00:00-0800 |   'active' | 't1' 
     'zzz' |           200 |          200 |          200 | 1972-01-01 04:00:00-0800 | 'disabled' | 't2' 
     'zzz' |           200 |          200 |          200 | 1973-01-01 04:00:00-0800 |   'active' | 't2' 
     'zzz' |           200 |          200 |          200 | 1973-01-01 04:00:00-0800 | 'disabled' | 't1' 
     'zzz' |           200 |          200 |          200 | 1974-01-01 04:00:00-0800 |   'active' | 't3'

Here are some queries that fail unexpectedly.

cqlsh:testing> select * from mydata where key1 = 'zzz' and key2 = 200 and key3 = 200 and key4 = 200;

(0 rows)

cqlsh:testing> select * from mydata where key1 = 'zzz' and key2 = 200 and key3 = 200 and key4 = 200 and status = 'active' and statustime = '1974-01-01 04:00:00-0800';

(0 rows)

What am I doing wrong?


Solution

  • From your output looks like you are writing key1 containing also the ' character, try this:

    select * from mydata where key1 = '''zzz''' and key2 = 200 and key3 = 200 and key4 = 200;
    

    HTH, Carlo