-- Po_info is the main table, po_item is the slave table, and po_info contains the updated field lastupdatetime, which is the associated field po_id of the two tables.
On update cascade postgresql
--------------- Po_id: Use a trigger to monitor table updates and use lastupdatetime to record time ------------------
-- Trigger creation process --
Create or replace function po_info ()
Returns trigger
postgresql update
$ Body $
Begin
If (tg_op = 'update') then
If new. lastupdatetime = old. lastupdatetime then
Update po_info set lastupdatetime = now () Where po_id = new. po_id;
postgresql update from select
End if;
End if;
Return NULL;
End;
update postgresql
$ Body $ language plpgsql
-- Create a trigger --
Create trigger tr_po_info
After update on po_info
For each row execute procedure po_info ();
--------------- Po_item uses the trigger to monitor table updates and change the lastupdatetime time of po_id ------------------
-- Trigger creation process --
Create or replace function po_item ()
Returns trigger
$ Body $
postgresql update join
Begin
If (tg_op = 'update') then
If (New! = Old) then
Update po_info P1 set lastupdatetime = now () Where p1.po _ id = new. po_id;
End if;
End if;
Return NULL;
End;
python postgresql update
$ Body $ language plpgsql
-- Create a trigger --
Create trigger tr_po_item
After update on po_item
For each row execute procedure po_item ();