Referencing external table in update/insert triggers - Mailing list pgsql-sql

From Amitabh Kant
Subject Referencing external table in update/insert triggers
Date
Msg-id 84b68b3d1002170718s5da61fam69de31ad1e54595f@mail.gmail.com
Whole thread Raw
Responses Re: Referencing external table in update/insert triggers  (Richard Huxton <dev@archonet.com>)
List pgsql-sql
Hi<br /><br />I have the following table structure for which I am trying to set a AFTER INSERT or UPDATE trigger:<br
/><br/>CREATE OR REPLACE FUNCTION update_data() RETURNS TRIGGER AS $update_data$<br />BEGIN<br />    IF NEW.t1f4 >
t2.t2f4<br/>         UPDATE t2 set t2f2=NEW.t1f2, t2f3=NEW.t1f3, t2f4=NEW.t1f4 where t2f1=NEW.d1;<br />        RETURN
NEW;<br/>    END IF;<br />END;<br />$update_data$ LANGUAGE plpgsql;<br /><br />[t1]<br />t1f1 integer <br />t1f2
integer<br/>t1f3 integer<br /> t1f4 timestamp without time zone<br />t1f5 character varying<br />t1f6 real<br />d1
bigint [fk: t2->t2f1]<br /><br />CREATE TRIGGER test_trigger AFTER INSERT OR UPDATE ON t1 FOR EACH ROW EXECUTE
PROCEDUREupdate_data();<br /><br /> [t2]<br />t2f1 integer NOT NULL<br />t2f2 integer<br />t2f3 integer<br />t2f4
timestampwithout time zone<br /><br />I would like to compare the date present in the t2f4 with the new data being
updatedthrough the trigger.  Using the if line as listed above returns an error. Is it possible to reference table t2
withinthe same trigger? I could also use another trigger (BEFORE UPDATE) on t2 to achieve the same, but would like to
avoidit.<br /><br />With regards<br /><br />Amitabh<br /> 

pgsql-sql by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: very frustrating feature-bug
Next
From: Tom Lane
Date:
Subject: Re: very frustrating feature-bug