Re: After Update Triggers - Mailing list pgsql-general

From Tomas Vondra
Subject Re: After Update Triggers
Date
Msg-id 455E57A4.6040503@fuzzy.cz
Whole thread Raw
In response to Re: After Update Triggers  (Bob Pawley <rjpawley@shaw.ca>)
List pgsql-general
> I am attempting to distribute the fluid from the process table to its
> own table (pipe or equipment) depending on whether the fluid is
> classified as op, ip or eq.

OK, now I understand.

> I didn't include the after insert trigger as there can't be a trigger
> until the ip_op_equipment is updated.

Please post both triggers and prefferably a small testcase - for example
seveal SQL commands (INSERTs / UPDATEs) demonstrating a failure.

I don't understand what do you mean by "there can't be a trigger until
the ip_op_equipment is updated". Well, by the time the AFTER UPDATE
trigger is fired, the update is already done (that's the AFTER keyword),
but I don't understand on what table is the trigger defined etc.

> BTW what is TG_OP that you referred to?

That's one of the variables defined by PL/pgSQL in each trigger. For
example this one means 'TRIGGERING OPERATION' - a trigger can be defined
for several operations simultaneously (AFTER INSERT OR UPDATE OR
DELETE), and in the body you can do something like

  IF TG_OP = 'INSERT' THEN
    ...
  ELSIF TG_OP = 'UPDATE' THEN
    ...
  ELSE
    ...
  END IF;

There are several other useful variables - see the this

  http://www.postgresql.org/docs/8.1/interactive/plpgsql-trigger.html

Tomas

pgsql-general by date:

Previous
From: "Jeremy Smith"
Date:
Subject: Re: PostgreSQL: Question about rules
Next
From: Jeff Davis
Date:
Subject: Re: PostgreSQL: Question about rules