Search code examples
cassandranosqlcql

Cassandra Primary Key allows duplicates


I tried inserting two record with all same values for columns in Primary Key in a Cassandra table and insert was successful. I am new to Cassandra and thought Primary Keys in Cassandra would not allow duplicate insertion. Is that incorrect? Following are the columns in my Primary key

PRIMARY KEY ((customer_id, source_id ), status_code, create_timestamp, modified_timestamp)

Following is how I am inserting

insert into testkeyspace.customers 
(customer_id, source_id, status_code,
 create_timestamp, modified_timestamp) 
value ('123e4567-e89b-12d3-a456-426655440000', 
1122334455, 0, toTimestamp(now()), toTimestamp(now()));

Solution

  • An important thing to note is the C* does not specifically disallow having duplicate values for a primary key. Having a duplicate value will overwrite the previous value (based on writetime), there will be no client messages to indicate this is happening. You will only notice on subsequent reads.