You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Ali Akhtar <al...@gmail.com> on 2016/11/01 12:22:31 UTC

Specifying multiple conditions for lightweight conditions?

In the following query:

UPDATE project SET last_due_at = '2013-01-01 00:00:00+0200'
WHERE id = '1'
IF last_due_at < '2013-01-01 00:00:00+0200';

The intent is to change the value of 'last_due_at' as long as 'last_due_at'
isn't already set to a later date than the one I've supplied.

The problem is, last_due_at starts off with an initial value of null, so
the above query fails.

If I try the following:


UPDATE project SET last_due_at = '2013-01-01 00:00:00+0200'
WHERE id = '1'
IF last_due_at < '2013-01-01 00:00:00+0200' OR last_due_at = null;

That fails due to a syntax error.

Is there any other way to achieve this?

Re: Specifying multiple conditions for lightweight conditions?

Posted by Vladimir Yudovin <vl...@winguzone.com>.
Hi,



Unfortunately CQL syntax doesn't allow use of OR operator in condition list: 



UPDATE [ keyspace_name. ] table_name [ USING TTL time_value | USING TIMESTAMP timestamp_value ] SET assignment [ , assignment ] . . . WHERE row_specification [ IF EXISTS | IF NOT EXISTS | IF condition [ AND condition ] . . . ] ;



The simplest solution to make two different request, first with null check:



UPDATE project SET last_due_at = '2013-01-01 00:00:00+0200' WHERE id = '1' IF last_due_at = null;

then test result, if applied = False make second request:



UPDATE project SET last_due_at = '2013-01-01 00:00:00+0200' WHERE id = '1' IF last_due_at &lt; '2013-01-01 00:00:00+0200'



Sure, it's less effective then OR condition. Probably you can use IF NOT EXISTS in first request (depending on your application logic), may be it will be slightly faster (not sure).





Best regards, Vladimir Yudovin, 

Winguzone - Hosted Cloud Cassandra
Launch your cluster in minutes.





---- On Tue, 01 Nov 2016 08:22:31 -0400Ali Akhtar &lt;ali.rac200@gmail.com&gt; wrote ----




In the following query:



UPDATE project SET last_due_at = '2013-01-01 00:00:00+0200'

WHERE id = '1' 

IF last_due_at &lt; '2013-01-01 00:00:00+0200';




The intent is to change the value of 'last_due_at' as long as 'last_due_at' isn't already set to a later date than the one I've supplied.



The problem is, last_due_at starts off with an initial value of null, so the above query fails.



If I try the following:





UPDATE project SET last_due_at = '2013-01-01 00:00:00+0200'


WHERE id = '1' 

IF last_due_at &lt; '2013-01-01 00:00:00+0200' OR last_due_at = null;




That fails due to a syntax error.



Is there any other way to achieve this?