DataStax Academy FAQ

DataStax Academy migrated to a new learning management system (LMS) in July 2020. We are also moving to a new Cassandra Certification process so there are changes to exam bookings, voucher system and issuing of certificates.

Check out the Academy FAQ pages for answers to your questions:


question

376752150_179413 avatar image
376752150_179413 asked ·

How can I implement an INSERT into table B that is conditional on table A?

I have two tables A and B.

How to implement the following logic?

If a doesn't exists in A: insert a into A and insert b into B. [NOTE: the insertions of a and b must be "Cassandra batch" style.]

If a exist in A, don't insert b into B.


lightweight transactions
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.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

Lightweight transactions only provide isolation on a per-table basis.

It is not possible to do a conditional write (INSERT, UPDATE, DELETE) to table B based on the existence of a partition in table A. You can only specify a condition based on table B if you're writing to table B.

You will need to implement that logic in your application. Cheers!

[UPDATE] In the case where you want to do a conditional BATCH update, writing to multiple tables is not supported. Conditional batch updates can only contain statements for one table.

Again, the solution is to implement it in your application. Be aware that a read-before-write is expensive so use it sparingly.

1 comment 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.

thanks Erick. Sorry that my origin quesion was wrong. Now I refined the description.

Any insights would be much appreciated!

0 Likes 0 · ·