can a trigger on insert -> update other tables? - Mailing list pgsql-general

From will trillich
Subject can a trigger on insert -> update other tables?
Date
Msg-id 20010302151319.B26218@mail.serensoft.com
Whole thread Raw
Responses Re: can a trigger on insert -> update other tables?  (brichard@cafod.org.uk (Bruce Richardson))
List 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@serensoft.com
http://www.dontUthink.com/

pgsql-general by date:

Previous
From: will trillich
Date:
Subject: Re: how to examin the database structure with an sql command
Next
From: adb
Date:
Subject: Can you list the text of a proc in psql?