I have 2 tables "sellings" and "products". The table "produts" has an id column and an amount column. I want to create a trigger that when I insert a new sell in "sellings" it removes 1 from "amount" in "products". How can I do it?
My trigger function:
CREATE OR REPLACE FUNCTION public.sell()
RETURNS trigger
LANGUAGE 'plpgsql'
VOLATILE
COST 100
AS $BODY$
BEGIN
NEW."amount" := product.amount - 1;
RETURN NEW;
END
$BODY$;