ppatidar
ppatidar

Reputation: 177

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()));

Upvotes: 3

Views: 3199

Answers (2)

RussS
RussS

Reputation: 16576

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.

Upvotes: 3

Robbie
Robbie

Reputation: 19510

You're using toTimestamp(now()) for 2 of the clustering columns in your primary key, so its unlikely that the 2 inserted records have exactly the same values for those columns, i.e. the two records are not duplicates.

Take a look at this answer to a similar question

Upvotes: 3

Related Questions