0

Hello I am very new to Cassandra and have begun to learn it a couple days ago. I have a question when it comes to if not exist function. Does if not exist work on only 1 column ? . My concern is that if I have a column family that contains 3 properties such as

ID(UUID: Primary Key) , Email(Text) and Name(Text) . and have this saved in database

        1,   "MyEmail@gmail.com"  ,   "John"

If someone else tries to register and puts "DifferentEmail@gmail.com" and "John" as the name will this pass and be accepted ? There will obviously be people with the same name and different emails and I would not want that Insertion to be rejected. I essentially just want to reject the Insertion if the email already exist in the database and nothing else .

Ignacio Perez
  • 2,341
  • 3
  • 13
  • 18

1 Answers1

1

When you do an INSERT … IF NOT EXISTS then it ensures that insert is done only when a record does not exists with the same PK. Remember that without IF EXISTS clause it will be like an UPDATE for that PK i.e. INSERT using same PK is just an UPDATE in Cassandra and if you don't want this behavior then that’s where IF NOT EXISTS aka Lightweight Transaction (LWT) helps. So in your case if someone else puts “DifferentEmail@gmail.com" and "John" then it will go ahead as long as ID is different. Note that ‘IF NOT EXISTS’ here is just ensuring that an existing ID value is not overwritten. Since your ID is of UUID type so it seems like you may end up with same email address for different IDs which I guess may not be what you want. If you want to reject the insertion if email already exists then it will be better to use email_address as PK and that will ensure that no insert with existing PK is allowed.

dwivedialok
  • 151
  • 5