Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()));
like image 556
ppatidar Avatar asked Jan 01 '26 13:01

ppatidar


2 Answers

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.

like image 94
RussS Avatar answered Jan 05 '26 20:01

RussS


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

like image 37
Robbie Avatar answered Jan 05 '26 21:01

Robbie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!