Re: Rules and Triggers
От
Ross J. Reedstrom
Тема
Re: Rules and Triggers
Дата
Msg-id
20020910232816.GA3983@rice.edu
Ответ на
Re: Rules and Triggers (Michael Paesold)
Список
Дерево обсуждения
Re: POSIX-style regular expressions "Goran Buzic" <goran.buzic@hep.hr>
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
В списке pgsql-sql по дате отправления