pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
trigger AFTER INSERT
4+ messages / 3 participants
[nested] [flat]

* trigger AFTER INSERT
@ 2010-08-12 14:58  Josi Perez (3T Systems) <josiperez3t@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Josi Perez (3T Systems) @ 2010-08-12 14:58 UTC (permalink / raw)
  To: pgsql-admin

Hi,

I think that I have a conceptual problem and I hope anyone could help me.

If I write a trigger AFTER INSERT and I have one error in this trigger, the
record (that I think was already inserted) is not inserted.
Example:

INSERT INTO tableX <record1>
trigger sumRecords AFTER INSERT under tableX to accumulate the records
inserted by hour
if there is an error in the commands executed for this record, <record1> is
not in the tableX

If this occurs in a trigger BEFORE INSERT, I can understand, but, if it is
AFTER INSERT, I believe that the record is already inserted.
What is wrong on it?

Thanks in advance
Josi Perez

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

* Re: trigger AFTER INSERT
@ 2010-08-12 15:00  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Josi Perez (3T Systems) <josiperez3t@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2010-08-12 15:00 UTC (permalink / raw)
  To: Josi Perez (3T Systems) <josiperez3t@gmail.com>; +Cc: pgsql-admin

"Josi Perez (3T Systems)" <josiperez3t@gmail.com> writes:
> If I write a trigger AFTER INSERT and I have one error in this trigger, the
> record (that I think was already inserted) is not inserted.

Sure, because the whole transaction is rolled back on error.

			regards, tom lane



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

* Re: trigger AFTER INSERT
@ 2010-08-16 16:06  Josi Perez (3T Systems) <josiperez3t@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Josi Perez (3T Systems) @ 2010-08-16 16:06 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin

Thank you for your answer.
Without considering the errors, the transaction should not start after the
AFTER INSERT?
Josi Perez


2010/8/12 Tom Lane <tgl@sss.pgh.pa.us>

> "Josi Perez (3T Systems)" <josiperez3t@gmail.com> writes:
> > If I write a trigger AFTER INSERT and I have one error in this trigger,
> the
> > record (that I think was already inserted) is not inserted.
>
> Sure, because the whole transaction is rolled back on error.
>
>                        regards, tom lane
>

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

* Re: trigger AFTER INSERT
@ 2010-08-16 16:39  Kevin Grittner <Kevin.Grittner@wicourts.gov>
  parent: Josi Perez (3T Systems) <josiperez3t@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Kevin Grittner @ 2010-08-16 16:39 UTC (permalink / raw)
  To: Josi Perez (3T Systems) <josiperez3t@gmail.com>; +Cc: pgsql-admin; Tom Lane <tgl@sss.pgh.pa.us>

"Josi Perez (3T Systems)" <josiperez3t@gmail.com> wrote:
 
> Without considering the errors, the transaction should not start
> after the AFTER INSERT?
 
Anything happening in a trigger is always part of the same database
transaction as the database action which fired the trigger.
 
-Kevin



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


end of thread, other threads:[~2010-08-16 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12 14:58 trigger AFTER INSERT Josi Perez (3T Systems) <josiperez3t@gmail.com>
2010-08-12 15:00 ` Tom Lane <tgl@sss.pgh.pa.us>
2010-08-16 16:06   ` Josi Perez (3T Systems) <josiperez3t@gmail.com>
2010-08-16 16:39     ` Kevin Grittner <Kevin.Grittner@wicourts.gov>

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