Hi there

I was facing a similar requirement recently, e.g. UPDATE .... IF EXISTS and
I found a work-around.

CREATE TABLE my_table(
   partition_key int,
   duplicate_partition_key int,
   ....
   value text,
   PRIMARY KEY(partition_key));

 At the beginning, I tried to query with : UPDATE my_table SET value = ...
WHERE partition_key=xxx IF partition_key=xxx but I ran into "Bad Request:
PRIMARY KEY column 'id' cannot have IF conditions"

 So the idea is to create a duplicate column of the partition key. This
column is only set at the creation of the partition and never modified.
With this I can simulate an IF EXISTS using UPDATE:

 UPDATE my_table SET value = ... WHERE partition_key=xxx IF
duplicate_partition_key=xxx;



On Tue, Nov 18, 2014 at 8:33 PM, Brian O'Neill <b...@alumni.brown.edu>
wrote:

> Exactly.  Perfect.  Will do.
> Thanks Robert.
>
> -brian
>
> ---
>
> Brian O'Neill
>
> Chief Technology Officer
>
>
> *Health Market Science*
>
> *The Science of Better Results*
>
> 2700 Horizon Drive • King of Prussia, PA • 19406
>
> M: 215.588.6024 • @boneill42 <http://www.twitter.com/boneill42>  •
>
> healthmarketscience.com
>
>
> This information transmitted in this email message is for the intended
> recipient only and may contain confidential and/or privileged material. If
> you received this email in error and are not the intended recipient, or the
> person responsible to deliver it to the intended recipient, please contact
> the sender at the email above and delete this email and any attachments and
> destroy any copies thereof. Any review, retransmission, dissemination,
> copying or other use of, or taking any action in reliance upon, this
> information by persons or entities other than the intended recipient is
> strictly prohibited.
>
>
>
>
> From: Robert Stupp <sn...@snazy.de>
> Reply-To: <user@cassandra.apache.org>
> Date: Tuesday, November 18, 2014 at 2:26 PM
> To: <user@cassandra.apache.org>
> Subject: Re: IF NOT EXISTS on UPDATE statements?
>
>
> For (2), we would love to see:
> UPSERT value=new_value where (not exists || value=read_value)
>
>
> That would be something like "UPDATE … IF column=value OR NOT EXISTS“.
>
> Took at the C* source and that feels like a LHF (for 3.0) so I opened
> https://issues.apache.org/jira/browse/CASSANDRA-8335 for that.
> Fell free to comment on that :)
>
>

Reply via email to