Re: Rule or Function and Trigger? - Mailing list pgsql-general

From Tom Lane
Subject Re: Rule or Function and Trigger?
Date
Msg-id 1618.1238770704@sss.pgh.pa.us
Whole thread Raw
In response to Rule or Function and Trigger?  ("James B. Byrne" <byrnejb@harte-lyne.ca>)
Responses Re: Rule or Function and Trigger?
List pgsql-general
"James B. Byrne" <byrnejb@harte-lyne.ca> writes:
> I am beginning to migrate some functionality from an application
> prototype into the DBMS.  One of these elements is time stamping row
> insertions and updates.

> I have been reading about rules, functions and triggers in regards
> to this issue.  So, of course, now I have myself completely
> befuddled.  From what I can determine from the documentation, it
> makes little difference to the DBMS whether I set a rule on insert
> and one on update for each table or define a function and set a
> trigger for insert or update on each table.

> If this is indeed the case then which way is the preferred method?

A trigger is very much preferred.  Rules are not as easy as they look.
Triggers are a bit more notationally cumbersome, but they tend to
do what you expect without any surprises.

For the problem you mention, a stripped-down version of the first
example here is what you want:
http://www.postgresql.org/docs/8.3/static/plpgsql-trigger.html

            regards, tom lane

pgsql-general by date:

Previous
From: Sam Mason
Date:
Subject: Re: reducing IO and memory usage: sending the content of a table to multiple files
Next
From: rafalak
Date:
Subject: Re: slow select in big table