Beyond two columns
We've now seen a table with two columns in its primary key: a partition key and a clustering column. As it turns out, neither of these roles is limited to a single column. A table can define one or more partition key columns and zero or more clustering columns.
Multiple clustering columns
Clustering columns are not limited to one field as specified before. Let's take a look at how multiple clustering columns work and facilitate data ordering. To illustrate this, we will recreate our status updates table so that it is clustered by the date and time when the user updated their status:
CREATE TABLE "user_status_updates_by_datetime" ( "username" text, "status_date" date, "status_time" time, "body" text, PRIMARY KEY ("username", "status_date", "status_time") );
We have created a new table user_status_updates_by_datetime
as shown next:
- Partition key:
username
, which is a text field. - Clustering columns:
status_date
andstatus_time
. Rows for a particular username are...