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()));
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With