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 22:42:35
Message-ID: 0514c201-42f8-2cf4-2325-015ef78f65bb@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/22/19 3:21 PM, PegoraroF10 wrote:
> sorry, I wasn´t clear, when I sad returning Null I tried to say that new.PK
> was Null, not the function result > Try to create exactly what I sent you and you´ll see null values on
that pk.

Yes because FOR EACH STATEMENT may deal with multiple rows, so it is
undefined what NEW.pk is referring to.

More below.

> And that occurs just because that trigger was created without EACH
> ROW/STATEMENT.
> So, my question is, PG should return an error and not create that trigger
> because ROW/STATEMENT was not specified, correct ?

It was implicitly specified. Per the docs it will be FOR EACH STATEMENT
by default in the absence of user input.

If you just need the new PK why not?:

INSERT INTO some_table ... RETURNING pk;

>
>
>
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
>
>
>

--
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 2019-05-22 22:45:09 Re: Trigger bug ?
Previous Message PegoraroF10 2019-05-22 22:40:57 Re: Trigger bug ?