From: Ross J. Reedstrom <reedstrm@rice.edu>
To: Michael Paesold <mpaesold@gmx.at>
Cc: Adam Erickson <adamre@cox.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Rules and Triggers
Date: Tue, 10 Sep 2002 18:28:16 -0500
Message-ID: <20020910232816.GA3983@rice.edu> (raw)
In-Reply-To: <007c01c25902$9772b940$4201a8c0@beeblebrox>
References: <ALEKKHACBIAEBNBPFKPCGEJNEKAA.adamre@cox.net>
<007c01c25902$9772b940$4201a8c0@beeblebrox>
On Tue, Sep 10, 2002 at 09:45:16PM +0200, Michael Paesold wrote:
>
> Adam Erickson wrote:
>
> > Correct me if I'm wrong, but rules constrain the SQL (ie. validation).
> > Triggers are carried out after the SQL is executed and the data is
> modified.
> > So, to answer your question, I think rules come first. As to which order
> > the rules / triggers are executed probably depends on the order you put
> them
> > in when you created them but I pulled that straight out of my arse. :)
>
> That would be correct for triggers with AFTER INSERT/UPDATE/DELETE.
> But what about triggers BEFORE INSERT/UPDATE/DELETE?
An important thing to remember about rules vs. triggers: Rules operate
on an SQL _query_ that involves the table (or view) that the rule is
attached to, whereas triggers operate on the individual _tuples_ of the
table they are attached to. Rules act to rewrite the incoming query,
at the very earliest step: just after parsing, but before planning and
optimizing. So rules _always_ act first. Triggers act when storage gets
hit: when the optimizer has choosen a plan, and passes it to the executor
for, well, execution.
Ross
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: reedstrm@rice.edu, mpaesold@gmx.at, adamre@cox.net
Subject: Re: Rules and Triggers
In-Reply-To: <20020910232816.GA3983@rice.edu>
* 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