Database Reference
In-Depth Information
concerning. This is the reason it is suggested to use light weight transaction, where it is a
must.
One such example can be the case where users are registering with unique usernames. You
will not want two users inserting the same name, because being unique it will act as an
identifier, which is used to fetch user records or log them in.
Light weight transactions can be used during insert or update. Here's an example:
# Create an ordinary table
CREATE TABLE lwt_demo (id int PRIMARY KEY, name text,
passwd text);
# Insert only iof the id column wasn't already taken
INSERT INTO lwt_demo (id, name, passwd) VALUES ( 1,
'Derek', 's3cr3t') IF NOT EXISTS;
[applied]
-----------
True
# If it is taken, the query returns the existing value with
a hint that this query/mutation was not applied
INSERT INTO lwt_demo (id, name, passwd) VALUES ( 1,
'Maverick', '0p3ns3cr3t') IF NOT EXISTS;
[applied] | id | name | passwd
-----------+----+-------+--------
False | 1 | Derek | s3cr3t
# In update you do not need to depend on the primary key.
Search WWH ::




Custom Search