From: Adrian Klaver <adrian.klaver@aklaver.com>
To: PegoraroF10 <marcos@f10.com.br>
To: pgsql-general@postgresql.org
Subject: Re: Trigger bug ?
Date: Wed, 22 May 2019 14:37:35 -0700
Message-ID: <baf9bba2-30c5-d1f4-0055-033b631fa365@aklaver.com> (raw)
In-Reply-To: <1558560792308-0.post@n3.nabble.com>
References: <1558560792308-0.post@n3.nabble.com>
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.klaver@aklaver.com
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, marcos@f10.com.br
Subject: Re: Trigger bug ?
In-Reply-To: <baf9bba2-30c5-d1f4-0055-033b631fa365@aklaver.com>
References: <1558560792308-0.post@n3.nabble.com> <baf9bba2-30c5-d1f4-0055-033b631fa365@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