cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sylvain Lebresne (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CASSANDRA-8610) Allow IF EXISTS for UPDATE statements
Date Wed, 04 Feb 2015 10:04:34 GMT

    [ https://issues.apache.org/jira/browse/CASSANDRA-8610?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14304868#comment-14304868
] 

Sylvain Lebresne commented on CASSANDRA-8610:
---------------------------------------------

I think we just forgot about it, no other non-obvious reason as far as I remember.


> 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)

Mime
View raw message