Reputation: 305
I want to use two fields as primary key (without clustering key).
PRIMARY KEY ((a, b)) => is that means a + b is the primary key, right? Or is it just partition key?
I'm confused
Upvotes: 1
Views: 1142
Reputation: 16393
To add to Aaron's response, the brackets ((
and )
) combine the 2 columns into one partition key. This means that you need to provide both columns in your filter in order to query the table:
SELECT ... FROM ... WHERE a = ? AND b = ?
Neither of these queries are valid because they only filter on 1 of the 2:
SELECT ... FROM ... WHERE a = ?
SELECT ... FROM ... WHERE b = ?
For what it's worth, I've explained the terms "composite partition key" and "compound primary key" with some real examples to illustrate the differences in this post -- https://community.datastax.com/questions/6171/. Cheers!
Upvotes: 3
Reputation: 57808
A primary key definition of:
PRIMARY KEY ((a, b))
...sets both a
and b
as a composite partition key. In this scenario, there is no clustering key.
This definition:
PRIMARY KEY (a, b)
...uses a
as the partition key and b
as the clustering key.
For more info, I recommend Carlo's famous answer to this question:
Difference between partition key, composite key and clustering key in Cassandra?
Upvotes: 4