Обсуждение: Multiple triggers/rules

Поиск
Список
Период
Сортировка

Multiple triggers/rules

От
brichard@cafod.org.uk (Bruce Richardson)
Дата:
How would I check the order triggers will be run in, where a
column/table has multiple triggers on it?  Is there a way to change that
order?

And while I'm at it, can you define more than one rule for the same
event on the one table?

--
Bruce

Re: Multiple triggers/rules

От
Tom Lane
Дата:
brichard@cafod.org.uk (Bruce Richardson) writes:
> How would I check the order triggers will be run in, where a
> column/table has multiple triggers on it?  Is there a way to change that
> order?

It's essentially random, and you can't control or change it.  If you
have interdependent actions in different triggers, you'll probably have
to combine those triggers so that you can know the ordering of the
actions.  If the triggers are independent, though, there's no reason
to care what order they fire in.

> And while I'm at it, can you define more than one rule for the same
> event on the one table?

Yes, with the same ordering issues as for triggers.

            regards, tom lane

Re: Multiple triggers/rules

От
brichard@cafod.org.uk (Bruce Richardson)
Дата:
On Wed, Feb 21, 2001 at 10:17:25AM -0500, Tom Lane wrote:
>
> > And while I'm at it, can you define more than one rule for the same
> > event on the one table?
>
> Yes, with the same ordering issues as for triggers.

OK, great.  Now - if a table has both a before-update trigger and an
DO (as opposed to DO INSTEAD) update rule and the trigger cancels the
update, is the update rule (or rules) cancelled?

--
Bruce

Re: Multiple triggers/rules

От
Tom Lane
Дата:
brichard@cafod.org.uk (Bruce Richardson) writes:
> OK, great.  Now - if a table has both a before-update trigger and an
> DO (as opposed to DO INSTEAD) update rule and the trigger cancels the
> update, is the update rule (or rules) cancelled?

No.  The trigger can only cancel the update of the specific tuple it's
being invoked for --- the query as a whole runs normally.  Indeed,
considering that ON UPDATE rules run before the original query, it'd
be difficult for a trigger on the original table to affect them.

You may have a conceptual problem here.  An ON UPDATE/DELETE rule
specifies an additional or substitute query to be run separately from
the initial UPDATE/DELETE query, but on the same tuple set (as achieved
by adding the initial query's WHERE clause to the rule's WHERE).  It's
not something you can turn on or off per affected tuple.  A trigger,
on the other hand, is fired separately for each tuple that a query is
about to (or just did) affect.  Triggers are a much lower-level
mechanism than rules.

            regards, tom lane