Re: Trigger questions

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Trigger questions
Date: 2023-05-04 14:30:56
Message-ID: eba74c9e-2460-61c2-047e-64105aee12d2@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/4/23 07:03, Justin wrote:
>
>
> On Thu, May 4, 2023 at 9:49 AM DAVID ROTH <adaptron(at)comcast(dot)net
> <mailto:adaptron(at)comcast(dot)net>> wrote:
>
> __
> 1) Can I create a trigger on a view?
> 2) Do triggers cascade?
>
> Say I have an insert trigger on a table.
> And, I have an insert trigger on a view that references this table
> If I do an insert on the view, will both triggers fire?
>
>
> Can not have triggers on Views,  Views use  RULES  which are DO INSTEAD.
> https://www.postgresql.org/docs/current/rules.html
> <https://www.postgresql.org/docs/current/rules.html>

That is wrong.

See

https://www.postgresql.org/docs/current/sql-createtrigger.html

The following table summarizes which types of triggers may be used on
tables, views, and foreign tables:

>
> Yes if you have an INSERT/UPDATE/DELETE rule on a view  that inserts
> into a table then that table's triggers will be executed.
>
> Please note RULES should  be avoided beyond the use case for VIEWS.
> RULES are executed very early in the query tree; it is not
> trivial to write rules on Tables.
>
> Thanks

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2023-05-04 14:42:33 Re: Trigger questions
Previous Message Justin 2023-05-04 14:03:45 Re: Trigger questions