From: Michael Davis <mdavis@sevainc.com>
To: 'Ramiro Arenas Ramirez' <ramiroa@coordinadora.com.co>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: RE: how to create this trigger?
Date: Thu, 1 Feb 2001 14:52:33 -0700
Message-ID: <01C08C5E.A0BFE940.mdavis@sevainc.com> (raw)
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?
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: mdavis@sevainc.com, ramiroa@coordinadora.com.co
Subject: Re: how to create this trigger?
In-Reply-To: <01C08C5E.A0BFE940.mdavis@sevainc.com>
References: <01C08C5E.A0BFE940.mdavis@sevainc.com>
* 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