pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
before insert for each row trigger on upsert
5+ messages / 3 participants
[nested] [flat]

* before insert for each row trigger on upsert
@ 2020-02-20 20:17 Ted Toth <txtoth@gmail.com>
  2020-02-20 20:32 ` Re: before insert for each row trigger on upsert Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Ted Toth @ 2020-02-20 20:17 UTC (permalink / raw)
  To: pgsql-general

I'm a little confused why the before insert trigger fires al all but since
it does is  there a way to know that an update will occur? Basically I
don't want the trigger affect the row on update.

Ted

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

* Re: before insert for each row trigger on upsert
  2020-02-20 20:17 before insert for each row trigger on upsert Ted Toth <txtoth@gmail.com>
@ 2020-02-20 20:32 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2020-02-20 21:03   ` Re: before insert for each row trigger on upsert Ted Toth <txtoth@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Adrian Klaver @ 2020-02-20 20:32 UTC (permalink / raw)
  To: Ted Toth <txtoth@gmail.com>; pgsql-general

On 2/20/20 12:17 PM, Ted Toth wrote:
> I'm a little confused why the before insert trigger fires al all but 
> since it does is  there a way to know that an update will occur? 

Because ON CONFLICT DO UPDATE is part of an INSERT command.

> Basically I don't want the trigger affect the row on update.

Not sure that a BEFORE trigger will work for that anyway as it will not 
have submitted the data yet for ON CONFLICT resolution.

> 
> Ted


-- 
Adrian Klaver
adrian.klaver@aklaver.com





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

* Re: before insert for each row trigger on upsert
  2020-02-20 20:17 before insert for each row trigger on upsert Ted Toth <txtoth@gmail.com>
  2020-02-20 20:32 ` Re: before insert for each row trigger on upsert Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-02-20 21:03   ` Ted Toth <txtoth@gmail.com>
  2020-02-20 21:43     ` Re: before insert for each row trigger on upsert Adrian Klaver <adrian.klaver@aklaver.com>
  2020-02-20 22:11     ` Re: before insert for each row trigger on upsert Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 5+ messages in thread

From: Ted Toth @ 2020-02-20 21:03 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general

On Thu, Feb 20, 2020 at 2:32 PM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

> On 2/20/20 12:17 PM, Ted Toth wrote:
> > I'm a little confused why the before insert trigger fires al all but
> > since it does is  there a way to know that an update will occur?
>
> Because ON CONFLICT DO UPDATE is part of an INSERT command.
>
> > Basically I don't want the trigger affect the row on update.
>
> Not sure that a BEFORE trigger will work for that anyway as it will not
> have submitted the data yet for ON CONFLICT resolution.
>

I think you are right in that the trigger doesn't change the row being
updated (which is good) but it also updates another table and that's what
I'd actually like to avoid on update.


> >
> > Ted
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>

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

* Re: before insert for each row trigger on upsert
  2020-02-20 20:17 before insert for each row trigger on upsert Ted Toth <txtoth@gmail.com>
  2020-02-20 20:32 ` Re: before insert for each row trigger on upsert Adrian Klaver <adrian.klaver@aklaver.com>
  2020-02-20 21:03   ` Re: before insert for each row trigger on upsert Ted Toth <txtoth@gmail.com>
@ 2020-02-20 21:43     ` Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Adrian Klaver @ 2020-02-20 21:43 UTC (permalink / raw)
  To: Ted Toth <txtoth@gmail.com>; +Cc: pgsql-general

On 2/20/20 1:03 PM, Ted Toth wrote:
> 
> 
> On Thu, Feb 20, 2020 at 2:32 PM Adrian Klaver <adrian.klaver@aklaver.com 
> <mailto:adrian.klaver@aklaver.com>> wrote:
> 
>     On 2/20/20 12:17 PM, Ted Toth wrote:
>      > I'm a little confused why the before insert trigger fires al all but
>      > since it does is  there a way to know that an update will occur?
> 
>     Because ON CONFLICT DO UPDATE is part of an INSERT command.
> 
>      > Basically I don't want the trigger affect the row on update.
> 
>     Not sure that a BEFORE trigger will work for that anyway as it will not
>     have submitted the data yet for ON CONFLICT resolution.
> 
> 
> I think you are right in that the trigger doesn't change the row being 
> updated (which is good) but it also updates another table and that's 
> what I'd actually like to avoid on update.

Hard to say what to do without knowing what the trigger function 
actually does?

> 
> 
>      >
>      > Ted
> 
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





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

* Re: before insert for each row trigger on upsert
  2020-02-20 20:17 before insert for each row trigger on upsert Ted Toth <txtoth@gmail.com>
  2020-02-20 20:32 ` Re: before insert for each row trigger on upsert Adrian Klaver <adrian.klaver@aklaver.com>
  2020-02-20 21:03   ` Re: before insert for each row trigger on upsert Ted Toth <txtoth@gmail.com>
@ 2020-02-20 22:11     ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 5+ messages in thread

From: Tom Lane @ 2020-02-20 22:11 UTC (permalink / raw)
  To: Ted Toth <txtoth@gmail.com>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general

Ted Toth <txtoth@gmail.com> writes:
> I think you are right in that the trigger doesn't change the row being
> updated (which is good) but it also updates another table and that's what
> I'd actually like to avoid on update.

Probably need to put that in an AFTER trigger, then.  By definition,
BEFORE triggers don't really know whether the insert is going to
happen.  This doesn't even require use of upsert to cause a problem:
a later BEFORE trigger could prevent the insertion, or change what
gets inserted.

			regards, tom lane





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


end of thread, other threads:[~2020-02-20 22:11 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20 20:17 before insert for each row trigger on upsert Ted Toth <txtoth@gmail.com>
2020-02-20 20:32 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-02-20 21:03   ` Ted Toth <txtoth@gmail.com>
2020-02-20 21:43     ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-02-20 22:11     ` Tom Lane <tgl@sss.pgh.pa.us>

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