Database Reference
In-Depth Information
... VALUES ('byron@domain',NOW())
... IF NOT EXISTS;
[applied]
|
email
|
created_on
-----------+--------------+--------------------------------------
False
|
byron@domain
|
9351e360-5fba-11e3-9b3a-a1e3c690259e
cqlsh:metrics> SELECT email,dateOf(created_on) AS
created_on
... FROM users;
email
|
created_on
--------------+--------------------------
byron@domain
|
2013-12-07 19:41:09-0800
(1 rows)
Updates also work mostly like their SQL counterparts, except that they
performan
upsert
bydefault.Muchlike
INSERT
overwritesdatainsteadof
failing,
UPDATE
performs an implicit insert if the primary key does not exist
in the dataset. This is actually quite useful for
COUNTER
columns, which
cannot be created using
INSERT
statements:
cqlsh:metrics> DROP TABLE counts;
cqlsh:metrics> CREATE TABLE counts(
customer_id INT,
metric TEXT,
value COUNTER,
PRIMARY KEY (customer_id, metric)
);
cqlsh:metrics> UPDATE counts SET
value = value + 1
WHERE customer_id = 1 AND metric = 'test';
cqlsh:metrics> SELECT * FROM counts;
customer_id
|
metric
|
value
-------------+--------+-------
1
|
test
|
1
(1 rows)
Update statements also support a check-and-set operation by appending
an
IF
statement with the same form as a
WHERE
clause to the end of the
statement. The update only succeeds if the
IF
statement evaluates to
true
.