Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created August 26, 2014 16:48
Show Gist options
  • Save thinkerbot/fde017245ec819f52498 to your computer and use it in GitHub Desktop.
Save thinkerbot/fde017245ec819f52498 to your computer and use it in GitHub Desktop.
Examples of cql queries
DROP KEYSPACE IF EXISTS example;
CREATE KEYSPACE example WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };
USE example;
DROP TABLE IF EXISTS xyz;
create table xyz (
xpart int,
x int,
z int,
y int,
PRIMARY KEY (xpart, x, z)
);
insert into xyz (xpart, z, x, y) values (0, 1, 1, 1);
insert into xyz (xpart, z, x, y) values (0, 1, 2, 2);
insert into xyz (xpart, z, x, y) values (0, 2, 2, 1);
insert into xyz (xpart, z, x, y) values (0, 2, 3, 2);
insert into xyz (xpart, z, x, y) values (0, 3, 3, 1);
insert into xyz (xpart, z, x, y) values (0, 3, 4, 2);
-- TRACING ON;
-- Queries using part key can be EQ/IN
-- Queries on cluster key(s) may be chained as long as the preceding is EQ
-- The final cluster key may use GT,LT,GTE,LTE
--
-- Can sort on the SECOND column, but that means you would have to always
-- be able to specify the second column as EQ to get to the third column.
select * from xyz;
select * from xyz where xpart = 0;
select * from xyz where xpart = 0 and x = 2;
select * from xyz where xpart = 0 and x >= 2 and x < 4;
select * from xyz where xpart = 0 and x = 3 and z > 2;
select * from xyz where xpart IN (0,1) and x >= 2 and x < 4;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment