Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 04C6D633F18 for ; Wed, 17 Feb 2010 11:20:29 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 91545-04 for ; Wed, 17 Feb 2010 15:20:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.27]) by mail.postgresql.org (Postfix) with ESMTP id 6BA39633A27 for ; Wed, 17 Feb 2010 11:18:49 -0400 (AST) Received: by qw-out-2122.google.com with SMTP id 5so1058963qwi.61 for ; Wed, 17 Feb 2010 07:18:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=7Yl/qfHWKEZ4sqvvXHYp+s2zVsGIhU5JGVYkXpWCSww=; b=TX23t3WbhQDnRXFr+1WE5IOQQsUfpfV88U9YufMVsQX89hwYQDCJetvQI86bsjXSqU nsuHGdjAEjqMaQEKXjhECcGKHzbRwW+biy5hetLlnH+ifJQw7pAV0p2pfCuiQTtWj/+t 4C3vPwIkidJK3QkH/DlLtxkffZ+L9hc4QryfA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=juWpI7JffWDLx4PtakLKRhVunlaFtq2x9E5qQewbBRorSrC1jsgkHlcov/RRQ+84M8 D5mwQWFivCLZNsdWjbIHYVAI+435PTsHkF1ZAjlJMGbWnd3bzgtmHydwBa7v2bD9GX/l xdUuhCYnhUytp1+dp4gukZV2OMh/wrgR6buio= MIME-Version: 1.0 Received: by 10.229.11.219 with SMTP id u27mr1592543qcu.10.1266419927213; Wed, 17 Feb 2010 07:18:47 -0800 (PST) From: Amitabh Kant Date: Wed, 17 Feb 2010 20:48:27 +0530 Message-ID: <84b68b3d1002170718s5da61fam69de31ad1e54595f@mail.gmail.com> Subject: Referencing external table in update/insert triggers To: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=0015175767cce5e9d3047fcd5d79 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.109 tagged_above=-10 required=5 tests=BAYES_05=-1.11, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201002/66 X-Sequence-Number: 33665 --0015175767cce5e9d3047fcd5d79 Content-Type: text/plain; charset=ISO-8859-1 Hi I have the following table structure for which I am trying to set a AFTER INSERT or UPDATE trigger: CREATE OR REPLACE FUNCTION update_data() RETURNS TRIGGER AS $update_data$ BEGIN IF NEW.t1f4 > t2.t2f4 UPDATE t2 set t2f2=NEW.t1f2, t2f3=NEW.t1f3, t2f4=NEW.t1f4 where t2f1=NEW.d1; RETURN NEW; END IF; END; $update_data$ LANGUAGE plpgsql; [t1] t1f1 integer t1f2 integer t1f3 integer t1f4 timestamp without time zone t1f5 character varying t1f6 real d1 bigint [fk: t2->t2f1] CREATE TRIGGER test_trigger AFTER INSERT OR UPDATE ON t1 FOR EACH ROW EXECUTE PROCEDURE update_data(); [t2] t2f1 integer NOT NULL t2f2 integer t2f3 integer t2f4 timestamp without time zone I would like to compare the date present in the t2f4 with the new data being updated through the trigger. Using the if line as listed above returns an error. Is it possible to reference table t2 within the same trigger? I could also use another trigger (BEFORE UPDATE) on t2 to achieve the same, but would like to avoid it. With regards Amitabh --0015175767cce5e9d3047fcd5d79 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi

I have the following table structure for which I am trying to set= a AFTER INSERT or UPDATE trigger:

CREATE OR REPLACE FUNCTION update= _data() RETURNS TRIGGER AS $update_data$
BEGIN
=A0=A0=A0 IF NEW.t1f4 = > t2.t2f4
=A0=A0=A0 =A0=A0=A0 UPDATE t2 set t2f2=3DNEW.t1f2, t2f3=3DNEW.t1f3, t2f4=3D= NEW.t1f4 where t2f1=3DNEW.d1;
=A0=A0=A0 =A0=A0=A0 RETURN NEW;
=A0=A0= =A0 END IF;
END;
$update_data$ LANGUAGE plpgsql;

[t1]
t1f1 = integer
t1f2 integer
t1f3 integer
t1f4 timestamp without time zone
t1f5 character varying
t1f6 real
= d1 bigint=A0 [fk: t2->t2f1]

CREATE TRIGGER test_trigger AFTER INS= ERT OR UPDATE ON t1 FOR EACH ROW EXECUTE PROCEDURE update_data();

[t2]
t2f1 integer NOT NULL
t2f2 integer
t2f3 integer
t2f4 times= tamp without time zone

I would like to compare the date present in t= he t2f4 with the new data being updated through the trigger.=A0 Using the i= f line as listed above returns an error. Is it possible to reference table = t2 within the same trigger? I could also use another trigger (BEFORE UPDATE= ) on t2 to achieve the same, but would like to avoid it.

With regards

Amitabh
--0015175767cce5e9d3047fcd5d79--