- class="PARAMETER">fromlist, be careful that the join
+ When a FROM> clause is present, what essentially happens
+ is that the target table is joined to the tables mentioned in the
+ fromlist, and each output row of the join
+ represents an update operation for the target table. When using
+ FROM> you should ensure that the join
produces at most one output row for each row to be modified. In
- other words, a target row mustn't join to more than one row from
+ other words, a target row shouldn't join to more than one row from
the other table(s). If it does, then only one of the join rows
will be used to update the target row, but which one will be used
is not readily predictable.
Attempt to insert a new stock item along with the quantity of stock. If
- the item exists, update the stock count of the existing item. To do this,
- use savepoints.
+ the item already exists, instead update the stock count of the existing
+ item. To do this without failing the entire transaction, use savepoints.
BEGIN;
+-- other operations
SAVEPOINT sp1;
INSERT INTO wines VALUES('Chateau Lafite 2003', '24');
--- Check for unique violation on name
+-- Assume the above fails because of a unique key violation,
+-- so now we issue these commands:
ROLLBACK TO sp1;
-UPDATE wines SET stock = stock + 24 WHERE winename='Chateau Lafite 2003';
+UPDATE wines SET stock = stock + 24 WHERE winename = 'Chateau Lafite 2003';
+-- continue with other operations, and eventually
COMMIT;
Compatibility
- This command conforms to the
SQL standard
. The
- FROM clause is a
+ This command conforms to the
SQL standard
, except
+ that the FROM clause is a
+
+ Some other database systems offer a FROM> option in which
+ the target table is supposed to be listed again within FROM>.
+ That is not how
PostgreSQL interprets
+ FROM>. Be careful when porting applications that use this
+ extension.
+