Re: Trigger bug ?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: PegoraroF10 <marcos(at)f10(dot)com(dot)br>, pgsql-general(at)postgresql(dot)org
Subject: Re: Trigger bug ?
Date: 2019-05-22 21:37:35
Message-ID: baf9bba2-30c5-d1f4-0055-033b631fa365@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/22/19 2:33 PM, PegoraroF10 wrote:
> We created a usual trigger which seemed to be not firing or not working
> properly. Then we put some raise notices on it and saw that it was returning
> Null values. But why, it´s after insert and is a primary key, cannot be
> null.

https://www.postgresql.org/docs/11/plpgsql-trigger.html
"The return value of a row-level trigger fired AFTER or a
statement-level trigger fired BEFORE or AFTER is always ignored; it
might as well be null. However, any of these types of triggers might
still abort the entire operation by raising an error."

More below.

>
> create function MyFunction() returns trigger as $$
> begin
> raise '%', new.MyPK;
> end$$ language plpgsql;
>
> create trigger MyTrigger after insert on MyTable execute procedure
> MyFunction();
>
> We forgot FOR EACH ROW/STATEMENT when created our trigger.
>
> On docs it´s written {ROW/STATEMENT} between {}, so it´s needed. But why did
> it accepted our command to create that trigger ?

https://www.postgresql.org/docs/11/sql-createtrigger.html
"FOR EACH ROW
FOR EACH STATEMENT

This specifies whether the trigger function should be fired once
for every row affected by the trigger event, or just once per SQL
statement. If neither is specified, FOR EACH STATEMENT is the default.
Constraint triggers can only be specified FOR EACH ROW.
"
>
>
>
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
>
>

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2019-05-22 22:01:06 Re: Trigger bug ?
Previous Message PegoraroF10 2019-05-22 21:33:12 Trigger bug ?