[ https://issues.apache.org/jira/browse/CASSANDRA-8610?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tyler Hobbs updated CASSANDRA-8610: ----------------------------------- Assignee: Prajakta Bhosale > 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 > Assignee: Prajakta Bhosale > 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)