cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Lin <wool...@gmail.com>
Subject Re: how to make unique coloumns in cassandra
Date Mon, 02 Mar 2015 11:45:32 GMT
Use a RDBMS 

There is a reason constraints were created and why Cassandra doesn't have it

Sent from my iPhone

> On Mar 2, 2015, at 2:23 AM, Rahul Srivastava <srivastava.robin71@gmail.com> wrote:
> 
> but what if i want to fetch the value using on table then this idea might fail
> 
>> On Mon, Mar 2, 2015 at 12:46 PM, Ajaya Agrawal <ajku.agr@gmail.com> wrote:
>> 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 conditions.
>> 
>> 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!
>> 
>> -Ajaya
>> 
>> Cheers,
>> Ajaya
>> 
>>> On Fri, Feb 27, 2015 at 5:26 PM, ROBIN SRIVASTAVA <srivastava.robin71@gmail.com>
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.
>>> 
> 

Mime
View raw message