Received: from mail01.phoenixdsl.com (mail.phoenixdsl.com [216.178.151.24]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f11Lqmq92058 for ; Thu, 1 Feb 2001 16:52:48 -0500 (EST) (envelope-from mdavis@sevainc.com) Received: (qmail 60841 invoked by uid 89); 1 Feb 2001 21:52:44 -0000 Received: from unknown (HELO SALLY) (64.32.157.45) by 0 with SMTP; 1 Feb 2001 21:52:44 -0000 Received: by localhost with Microsoft MAPI; Thu, 1 Feb 2001 14:52:41 -0700 Message-ID: <01C08C5E.A0BFE940.mdavis@sevainc.com> From: Michael Davis Reply-To: "mdavis@sevainc.com" To: "'Ramiro Arenas Ramirez'" , "pgsql-sql@postgresql.org" Subject: RE: how to create this trigger? Date: Thu, 1 Feb 2001 14:52:33 -0700 Organization: Seva Inc. X-Mailer: Microsoft Internet E-mail/MAPI - 8.0.0.4211 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Archive-Number: 200102/5 X-Sequence-Number: 1173 Did you insert a row into table2? What happens if there is no row in table 1 where id = code (of the newly inserted row in table2). Seems to me you many need to consider expanding increment_value() to check table1 to see if code exists. If not insert a new value, else update. -----Original Message----- From: Ramiro Arenas Ramirez [SMTP:ramiroa@coordinadora.com.co] Sent: Thursday, February 01, 2001 2:48 PM To: pgsql-sql@postgresql.org Subject: how to create this trigger? I need to create a trigger that increment a value in a column of table1 where a row is inserted in table 2 I have tried whit this but it just does nothing. CREATE FUNCTION increment_value () RETURNS opaque AS 'DECLARE code int4; BEGIN code := new.code; UPDATE table1 SET value = value + 1 WHERE id = code; RETURN NEW; END;' LANGUAGE 'plpgsql'; CREATE TRIGGER insert_on_table2 BEFORE INSERT ON table2 FOR EACH ROW EXECUTE PROCEDURE increment_value(); Can you help me?