Database Reference
In-Depth Information
So the format is, after the INSERT INTO keyword, goes the table name, then a comma-
separated list of columns, then the VALUES keyword, then a comma-separated list of val-
ues of appropriate types in the same order as the list of the columns. In case you want to
avoid concurrently writing threads to overwrite a row, you should use IF NOT EXISTS .
So, why not do this for all the insert queries? The answer is performance hit. We will
come to see why this happens soon in this section. You can set a TTL for the row. TTL is
a precondition that states the row will be deleted automatically after the specified time.
You can also optionally set TIMESTAMP ; this timestamp is used in conflict resolution. It
is also worth noting that the INSERT statements are not applicable to counter tables. So,
here are some examples:
# Create a simple table to insert data into
CREATE TABLE demo_insert (id int PRIMARY KEY, name text,
phone set<text>);
# Insert a simple row
INSERT INTO demo_insert (id, name, phone) VALUES ( 1,
'Harry Potter', {'44-234-0495','44-234-9845'});
# Insert a row with the same primary key
# check for duplicates this time
INSERT INTO demo_insert (id, name, phone) VALUES ( 1,
'Draco malfoy', {'44-234-0495','44-234-9845'}) IF NOT
EXISTS;
[applied] | id | name | phone
-----------+----+--------------+--------------------------------
False | 1 | Harry Potter | {'44-234-0495',
'44-234-9845'}
# Insert the same row with a different primary key; set its
life as 30 seconds
INSERT INTO demo_insert (id, name, phone) VALUES ( 2,
'Draco malfoy', {'44-234-4398'}) IF NOT EXISTS USING TTL 30;
[applied]
-----------
Search WWH ::




Custom Search