can a trigger on insert -> update other tables?

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: can a trigger on insert -> update other tables?
Date: 2001-03-02 21:13:19
Message-ID: 20010302151319.B26218@mail.serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

i've got a "_rating" table that, when a new record is added,
i'd like to have propagate through some other tables to update
running totals:

CREATE FUNCTION _rating_propagate( _rating ) RETURNS OPAQUE AS '
DECLARE

n ALIAS FOR $1;
opinion char(1) := upper(substring(n.rating from 1 for 1));

BEGIN

UPDATE sometable SET fld = fld + 1 WHERE id = .... ;
UPDATE othertable SET fld = fld + 1 WHERE id = .... ;
[yada yada]
END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER _rating_propagate
BEFORE INSERT ON _rating
FOR EACH ROW EXECUTE PROCEDURE _rating_propagate( NEW );

INSERT INTO _rating VALUES ( ... );

the insert into _rating works fine, but none of the other tables
are actually UPDATED. who's got the clue stick?

--
will(at)serensoft(dot)com
http://www.dontUthink.com/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message adb 2001-03-02 21:43:05 Can you list the text of a proc in psql?
Previous Message will trillich 2001-03-02 20:39:55 Re: how to examin the database structure with an sql command