Re: Query on exception handling in PL/pgSQL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: diya(dot)das(at)wipro(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Query on exception handling in PL/pgSQL
Date: 2004-11-26 19:06:52
Message-ID: 10529.1101496012@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

diya das <diyadas(at)yahoo(dot)com> writes:
> My pgsql function
> does an insert to a table and I have opened a
> transaction block before calling my function from the
> client. When the insert operation fails due to unique
> key violation the whole transaction aborts. Is there a
> way I can handle this error in my pgsql funtion rather
> that aborting and not executing the rest of the
> operations?

Not before PG 8.0. In earlier versions you might be able to work around
the problem by testing for existence of the target key before you
insert; though this has obvious race-condition problems if you expect
multiple clients to be doing it simultaneously.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Glen Eustace 2004-11-26 20:43:43 Problems setting up slony-1
Previous Message j0rd1 adame 2004-11-26 18:45:09 Re: [ok] Error after adding Foreign Keys