From: Ramiro Arenas Ramírez <ramiroa@coordinadora.com.co>
To: pgsql-sql@postgresql.org
Subject: how to create this trigger?
Date: Thu, 1 Feb 2001 16:48:28 -0500
Message-ID: <KJEFJKLOGBDOOKFDDKKLMEMGCCAA.ramiroa@coordinadora.com.co> (raw)
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?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: ramiroa@coordinadora.com.co
Subject: Re: how to create this trigger?
In-Reply-To: <KJEFJKLOGBDOOKFDDKKLMEMGCCAA.ramiroa@coordinadora.com.co>
References: <KJEFJKLOGBDOOKFDDKKLMEMGCCAA.ramiroa@coordinadora.com.co>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox