pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to tell which event was fired in Trigger function
5+ messages / 3 participants
[nested] [flat]

* How to tell which event was fired in Trigger function
@ 2018-07-11 17:36  Igal @ Lucee.org <igal@lucee.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Igal @ Lucee.org @ 2018-07-11 17:36 UTC (permalink / raw)
  To: pgsql-general

Hi,

I am writing a trigger function that is used after DELETE, INSERT, and 
UPDATE, like so:

     CREATE TRIGGER tr_name AFTER DELETE OR INSERT OR UPDATE ...

How can I tell inside the trigger function if the event was DELETE or 
INSERT/UPDATE?

The table has a `NOT NULL id` column, so I am thinking that maybe a 
DELETE will have a NULL value in NEW.id?  Will that work?  Is there a 
better way?

Thanks,

Igal Sapir
Lucee Core Developer
Lucee.org <http://lucee.org/;

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to tell which event was fired in Trigger function
@ 2018-07-11 17:38  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Igal @ Lucee.org <igal@lucee.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Adrian Klaver @ 2018-07-11 17:38 UTC (permalink / raw)
  To: Igal @ Lucee.org <igal@lucee.org>; pgsql-general

On 07/11/2018 10:36 AM, Igal @ Lucee.org wrote:
> Hi,
> 
> I am writing a trigger function that is used after DELETE, INSERT, and 
> UPDATE, like so:
> 
>      CREATE TRIGGER tr_name AFTER DELETE OR INSERT OR UPDATE ...
> 
> How can I tell inside the trigger function if the event was DELETE or 
> INSERT/UPDATE?
> 
> The table has a `NOT NULL id` column, so I am thinking that maybe a 
> DELETE will have a NULL value in NEW.id?  Will that work?  Is there a 
> better way?

https://www.postgresql.org/docs/10/static/plpgsql-trigger.html

> 
> Thanks,
> 
> Igal Sapir
> Lucee Core Developer
> Lucee.org <http://lucee.org/;
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to tell which event was fired in Trigger function
@ 2018-07-11 17:54  Igal @ Lucee.org <igal@lucee.org>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Igal @ Lucee.org @ 2018-07-11 17:54 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general

On 7/11/2018 10:38 AM, Adrian Klaver wrote:
> On 07/11/2018 10:36 AM, Igal @ Lucee.org wrote:
>> How can I tell inside the trigger function if the event was DELETE or 
>> INSERT/UPDATE?
>
> https://www.postgresql.org/docs/10/static/plpgsql-trigger.html

This looks like it have all of the information that I need.  For some 
reason search engines bring up many other pages but not that one.

Thanks Adrian!

Igal




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to tell which event was fired in Trigger function
@ 2018-07-11 18:02  David G. Johnston <david.g.johnston@gmail.com>
  parent: Igal @ Lucee.org <igal@lucee.org>
  0 siblings, 1 reply; 5+ messages in thread

From: David G. Johnston @ 2018-07-11 18:02 UTC (permalink / raw)
  To: Igal @ Lucee.org <igal@lucee.org>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general

On Wed, Jul 11, 2018 at 10:54 AM, Igal @ Lucee.org <igal@lucee.org> wrote:

> On 7/11/2018 10:38 AM, Adrian Klaver wrote:
>
>> On 07/11/2018 10:36 AM, Igal @ Lucee.org wrote:
>>
>>> How can I tell inside the trigger function if the event was DELETE or
>>> INSERT/UPDATE?
>>>
>>
>> https://www.postgresql.org/docs/10/static/plpgsql-trigger.html
>>
>
> This looks like it have all of the information that I need.  For some
> reason search engines bring up many other pages but not that one.
>

​For these situations I recommend bookmarking and navigating to the Table
of Contents [1] for the documentation and looking for relevant chapter
titles - in this case the "V. 38 - Triggers" one is right there on the main
page.

https://www.postgresql.org/docs/10/static/index.html

On a related note, maybe the pl/pgsql link from the Triggers chapter should
link directly to the Triggers section under pl/pgsql instead of the top of
the chapter...

David J.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to tell which event was fired in Trigger function
@ 2018-07-11 21:08  Igal @ Lucee.org <igal@lucee.org>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Igal @ Lucee.org @ 2018-07-11 21:08 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general

On 7/11/2018 11:02 AM, David G. Johnston wrote:
> On Wed, Jul 11, 2018 at 10:54 AM, Igal @ Lucee.org <igal@lucee.org 
> <mailto:igal@lucee.org>>wrote:
>
>     On 7/11/2018 10:38 AM, Adrian Klaver wrote:
>
>         On 07/11/2018 10:36 AM, Igal @ Lucee.org wrote:
>
>             How can I tell inside the trigger function if the event
>             was DELETE or INSERT/UPDATE?
>
>
>         https://www.postgresql.org/docs/10/static/plpgsql-trigger.html
>         <https://www.postgresql.org/docs/10/static/plpgsql-trigger.html;
>
>
>     This looks like it have all of the information that I need.  For
>     some reason search engines bring up many other pages but not that one.
>
>
> ​For these situations I recommend bookmarking and navigating to the 
> Table of Contents [1] for the documentation and looking for relevant 
> chapter titles - in this case the "V. 38 - Triggers" one is right 
> there on the main page.
>
> https://www.postgresql.org/docs/10/static/index.html
>
> On a related note, maybe the pl/pgsql link from the Triggers chapter 
> should link directly to the Triggers section under pl/pgsql instead of 
> the top of the chapter...

+1

Should link to ¶42.9 - 
https://www.postgresql.org/docs/10/static/plpgsql-trigger.html

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2018-07-11 21:08 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-07-11 17:36 How to tell which event was fired in Trigger function Igal @ Lucee.org <igal@lucee.org>
2018-07-11 17:38 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-07-11 17:54   ` Igal @ Lucee.org <igal@lucee.org>
2018-07-11 18:02     ` David G. Johnston <david.g.johnston@gmail.com>
2018-07-11 21:08       ` Igal @ Lucee.org <igal@lucee.org>

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