You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Prajakta Bhosale (JIRA)" <ji...@apache.org> on 2015/01/30 13:22:34 UTC

[jira] [Updated] (CASSANDRA-8610) Allow IF EXISTS for UPDATE statements

     [ https://issues.apache.org/jira/browse/CASSANDRA-8610?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Prajakta Bhosale updated CASSANDRA-8610:
----------------------------------------
    Attachment: 8610.patch

Check for if Exists

> 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
>         Attachments: 8610.patch
>
>
> 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)