-- See
select * from catalog;
select * from inventory;
select * from orders;

-- Correct order
update orders set amount = amount + 20 where order_id = 3;
select * from current_orders;
select order_id, item_name, amount, st, et from orders where order_id=3;

-- Cancel an order
delete from orders where order_id = 3;
select * from current_orders;
select * from orders;
-- Cannot update a cancelled order
update orders set amount = amount + 10 where order_id = 3;

-- Receive an order
select * from current_orders where order_id = 1;
select * from current_inventory where item_name = 'widgets';
select receive_order(1);
select * from current_orders;
select * from orders;
select * from current_inventory;
select * from inventory;

-- Sale of an item
update inventory set in_stock = in_stock - 11 where item_name = 'thisstuff';
select sale('thisstuff', 11);
select * from current_inventory;
select * from inventory;
select sale ('thingies',5);
-- At Time Selections
select * from inventory_at_time ( '2006-04-26 21:04:43.389516' );
select * from orders_at_time ( '2006-07-26 21:04:43.389516' );

-- Joining tables on the same time:
select i.item_name, i.in_stock, sum(o.amount) as on_order, 'xxx' as time
from inventory_at_time('xxx') i
left outer join orders_at_time('xxx') o
   on (i.item_name = o.item_name)
group by item_name, i.in_stock, time
order by i.item_name;
