Created
August 26, 2014 16:48
-
-
Save thinkerbot/fde017245ec819f52498 to your computer and use it in GitHub Desktop.
Examples of cql queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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