Received: from frithjof.reiner (b94.dialin.tuwien.ac.at [192.35.240.224]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f11N8kq98125 for ; Thu, 1 Feb 2001 18:08:47 -0500 (EST) (envelope-from areiner@tph.tuwien.ac.at) Received: (qmail 1347 invoked by uid 500); 1 Feb 2001 23:08:41 -0000 From: "Albert REINER" Date: Fri, 2 Feb 2001 00:08:41 +0100 To: pgsql-sql@postgresql.org Subject: Re: how to create this trigger? Message-ID: <20010202000841.A1197@frithjof> Mail-Followup-To: pgsql-sql@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-3 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i In-Reply-To: ; from ramiroa@coordinadora.com.co on Thu, Feb 01, 2001 at 04:48:28PM -0500 X-Archive-Number: 200102/7 X-Sequence-Number: 1175 Don't know much, but couldn't you let increment_value take an argument and run it on new.code? But maybe I am completely off. Albert. On Thu, Feb 01, 2001 at 04:48:28PM -0500, Ramiro Arenas Ramírez wrote: > 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? > > > > -- -------------------------------------------------------------------------- Albert Reiner Deutsch * English * Esperanto * Latine --------------------------------------------------------------------------