Database Reference
In-Depth Information
name | APPLE
in_stock | 500
reserved | 100
On checking the stock we see that indeed 100 apples are reserved:
postgres=# SELECT * FROM fruits_in_stock;
-[ RECORD 1 ]----
name | ORANGE
in_stock | 500
reserved | 0
-[ RECORD 2 ]----
name | APPLE
in_stock | 500
reserved | 100
If we change the offered amount, the reservation follows:
postgres=# UPDATE fruit_offer SET
offered_amount = 115 WHERE offer_id = 1;
UPDATE 1
postgres=# SELECT * FROM fruits_in_stock;
-[ RECORD 1 ]----
name | ORANGE
in_stock | 500
reserved | 0
-[ RECORD 2 ]----
name | APPLE
in_stock | 500
reserved | 115
We also get some extra benefits. First, because of the constraint on the stock table,
you can't sell the reserved apples:
postgres=# UPDATE fruits_in_stock SET in_stock
= 100 WHERE name = 'APPLE';
Search WWH ::




Custom Search