cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ajaya Agrawal <>
Subject Re: how to make unique coloumns in cassandra
Date Mon, 02 Mar 2015 07:16:25 GMT
Make a table for each of the unique keys. For e.g.

If primary key for user table is user_id and you want the phone number
column to be unique then create another table wherein the primary key is
(phone_number, user_id). Before inserting to main table try to insert to
this table first with "if not exists" clause. If it succeeds then go ahead
with your insert to the user table. Similarly while deleting a row from the
primary table delete the corresponding row in all other tables. The order
of insertion to tables matter here otherwise you would end up inducing race

The catch here is, you should not be updating the unique column ever. If
you do that you would have to use locks and if there are multiple nodes
running your application then you would need a distributed lock. I would
suggest not to update the unique columns. In stead force your users to
delete the entry and recreate it. If you can't do that you need to evaluate
your choice of database. Perhaps a relational database would be better
suited to your requirements.

Hope this helps!



On Fri, Feb 27, 2015 at 5:26 PM, ROBIN SRIVASTAVA <> wrote:

> I want to make unique constraint in cassandra . As i want that all the
> value in my column be unique in my column family ex: name-rahul phone-123
> address-abc
> now i want that in this row no values equal to rahul ,123 and abc get
> inserted again on searching on datastax i found that i can achieve it by
> doing query on partition key as IF NOT EXIST ,but not getting the solution
> for getting all the three values unique means if name- jacob phone-123
> address-qwe
> this should also be not inserted into my database as my phone column has
> the same value as i have shown with name-rahul.

View raw message