cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "DOAN DuyHai (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CASSANDRA-8610) Allow IF EXISTS for UPDATE statements
Date Tue, 13 Jan 2015 16:10:39 GMT
DOAN DuyHai created CASSANDRA-8610:
--------------------------------------

             Summary: Allow IF EXISTS for UPDATE statements
                 Key: CASSANDRA-8610
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-8610
             Project: Cassandra
          Issue Type: Improvement
          Components: API
         Environment: Cassandra 2.1.2
            Reporter: DOAN DuyHai
            Priority: Minor


While creating a hands-on exercice for Cassandra, I was facing a quite annoying limitation.


 Let's take this table:

{code:sql}
CREATE TABLE killrchat.chat_rooms(		
	room_name text,
	creation_date timestamp,
	banner text,
	creator text,
	participants set<text>,
PRIMARY KEY(room_name));
{code}

Upon a new participant joining the room, to be concurrency-proof (avoiding mutating the participants
set if the room is deleted concurrently), I would like to issue this query:

{code:sql}

 UPDATE chat_rooms SET participants = participants + {'johnny'} WHERE room_name = 'games'
IF EXISTS;
{code}

 Unfortunately the clause IF EXISTS is not allowed for UPDATE statements. Similarly I tried

{code:sql}

 UPDATE chat_rooms SET participants = participants + {'johnny'} WHERE room_name = 'games'
IF room_name='games';
{code}

 It doesn't work either, it is not allowed to use one column of the primary key as condition
column for LWT (why ? mystery).

 So far, the only work-around I found is:

{code:sql}

 UPDATE chat_rooms SET participants = participants + {'johnny'} WHERE room_name = 'games'
IF name='games';
{code}

 I added an extra column called *name* which is just the duplicate of the partition key *room_name*.
It does work but is not very elegant.

 I believe there are legit use cases for UPDATE ... IF EXISTS;





--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message