Database Reference
In-Depth Information
1
|
hits
|
1ae93880-5fb8-11e3-9b3a-a1e3c690259e
|
30
1
|
hits
|
19925b10-5fb8-11e3-9b3a-a1e3c690259e
|
15
1
|
hits
|
175897b0-5fb8-11e3-9b3a-a1e3c690259e
|
10
By default,
INSERT
statements overwrite data with the same primary key.
This is not the usual behavior for SQL databases, so it may come as a
surprise to some. This can cause problems in some situations, and, starting
with CQL3, Cassandra now supports a feature called Lightweight
Transactions that recover the SQL-like behavior by adding an
IF NOT
EXISTS
statementtotheendofthe
INSERT
statement.Forexample,ausers
table with a
created_on
field set to
NOW()
will be changed after every
insert unless the
IF NOT EXISTS
statement is used:
cqlsh:metrics> CREATE TABLE users(email TEXT PRIMARY
KEY,created_on
TIMEUUID);
cqlsh:metrics> INSERT INTO users(email,created_on)
... VALUES ('byron@domain',NOW());
cqlsh:metrics> SELECT email,dateOf(created_on) AS
created_on
... FROM users;
email
|
created_on
--------------+--------------------------
byron@domain
|
2013-12-07 19:40:24-0800
(1 rows)
cqlsh:metrics> INSERT INTO users(email,created_on)
... VALUES ('byron@domain',NOW());
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)
cqlsh:metrics> INSERT INTO users(email,created_on)