3
votes

In Cassandra, I understand that by default, given PRIMARY KEY(id1, id2), id1 will be partition key and id2 will be clustering key.

I want to know if can I define two partition keys without any clustering key as follows:

PRIMARY KEY ((id1, id2));
1

1 Answers

7
votes
  1. Your understanding is correct.
  2. Your PRIMARY KEY ((id1, id2)) is correct and you are specifying one partition key consisting of two columns.

In the second case, you can query the data only by specifying both columns values. EG:

SELECT * FROM mytable WHERE id1=1 AND id2=3;

and queries like:

SELECT * FROM mytable WHERE id1=1;

will fail because id2 is part of your primary key.