Re: Rules and Triggers

From: "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu>
To: Michael Paesold <mpaesold(at)gmx(dot)at>
Cc: Adam Erickson <adamre(at)cox(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Rules and Triggers
Date: 2002-09-10 23:28:16
Message-ID: 20020910232816.GA3983@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andres Sommerhoff 2002-09-11 03:43:59 R-Tree, GiST or B-Tree? I will need it?
Previous Message Lee Harr 2002-09-10 23:27:06 Re: Transaction Newbie