Re: [HACKERS] Trigger aborted on error

From: wieck(at)debis(dot)com (Jan Wieck)
To: akorud(at)polynet(dot)lviv(dot)ua (Andrij Korud)
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Trigger aborted on error
Date: 1999-10-31 21:32:51
Message-ID: m11i2ap-0003kLC@orion.SAPserv.Hamburg.dsh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> Hi.
> I've such problem :
> I table with primary key and in trigger try to insert into this table data
> wich violate constrain (not uniq). When ectually executing SPI_execp I got
> a message "ERROR: cannot insert a duplicate key into a unique index" and
> trigger executing is aborted. What should I do in order to get this error
> as a result from SPI_execp and continue trigger execution?
>
> Thanks in advance,
> Andriy Korud, Lviv, Ukraine

No chance, ERROR messages cannot be caught in any way by a
trigger. They abort the entire transaction.

The only possibility you have is to check via SELECT prior to
the INSERT. Unfortunately you would need an exclusive table
lock to avoid race conditions.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#========================================= wieck(at)debis(dot)com (Jan Wieck) #

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message gov-boi 1999-10-31 21:33:07 exploit update.
Previous Message Lamar Owen 1999-10-31 21:29:21 Re: [HACKERS] pgaccess 0.98