pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Trigger questions
Date: Thu, 4 May 2023 07:30:56 -0700
Message-ID: <eba74c9e-2460-61c2-047e-64105aee12d2@aklaver.com> (raw)
In-Reply-To: <CALL-XeNf3R2yukc4UxNrjpCyvV1x6CEdbe7q=Ww3ahh9N4Ya8g@mail.gmail.com>
References: <1215915755.69415.1683208156758@connect.xfinity.com>
	<CALL-XeNf3R2yukc4UxNrjpCyvV1x6CEdbe7q=Ww3ahh9N4Ya8g@mail.gmail.com>

On 5/4/23 07:03, Justin wrote:
> 
> 
> On Thu, May 4, 2023 at 9:49 AM DAVID ROTH <adaptron@comcast.net 
> <mailto:adaptron@comcast.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.klaver@aklaver.com






view thread (4+ messages)  latest in thread

Message-ID: <eba74c9e-2460-61c2-047e-64105aee12d2@aklaver.com>
Permalink:  ../eba74c9e-2460-61c2-047e-64105aee12d2@aklaver.com/
Also on:    postgresql.org/message-id/eba74c9e-2460-61c2-047e-64105aee12d2@aklaver.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com
  Subject: Re: Trigger questions
  In-Reply-To: <eba74c9e-2460-61c2-047e-64105aee12d2@aklaver.com>
  References: <1215915755.69415.1683208156758@connect.xfinity.com> <CALL-XeNf3R2yukc4UxNrjpCyvV1x6CEdbe7q=Ww3ahh9N4Ya8g@mail.gmail.com> <eba74c9e-2460-61c2-047e-64105aee12d2@aklaver.com>

* 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