Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

kingjaga28_177573 avatar image
kingjaga28_177573 asked ·

Why is there no error when overwriting a partition in Cassandra?

cqlsh:ruckus> create TABLE test(name text, id uuid, PRIMARY KEY(name));

cqlsh:ruckus> SELECT * from test;


name | id

------+----


(0 rows)

cqlsh:ruckus> INSERT INTO test (name,id ) VALUES ( 'John',uuid());

cqlsh:ruckus> SELECT * from test;


name | id

------+--------------------------------------

John | d43a0ef1-ac86-452b-9346-7001a6c78081


(1 rows)

cqlsh:ruckus> INSERT INTO test (name,id ) VALUES ( 'John',uuid());

cqlsh:ruckus> SELECT * from test;


name | id

------+--------------------------------------

John | b74adc5f-8b8c-47ec-8882-d105d976a042


(1 rows)

cqlsh:ruckus> SELECT * from test;


name | id

------+--------------------------------------

John | b74adc5f-8b8c-47ec-8882-d105d976a042


(1 rows)

cqlsh:ruckus>


unique error handling
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

ben.krug_85176 avatar image
ben.krug_85176 answered ·

Sean is correct. To add some further details, you can use LWTs, which are mentioned (eg) here, and there's a little more detail here, including mention of setting the serial consistency level. Also, there's an example of using this in a situation like yours here that I think might be helpful.

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

seandurity_18889 avatar image
seandurity_18889 answered ·

There is no error. Cassandra does not read before writing. If you need that kind of read before write, look at light-weight transactions ("if not exists"). Just be aware that LWT (also called CAS - compare and set) requires a distributed transaction and is slower and more taxing to the system.

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.