From: | "Jeff Eckermann" <jeckermann(at)verio(dot)net> |
---|---|
To: | "Francesco Casadei" <f_casadei(at)libero(dot)it>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Catching errors inside a function |
Date: | 2001-09-04 16:38:09 |
Message-ID: | 053601c1355f$fb01d0d0$279c10ac@INTERNAL |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Why not just do a SELECT to check for existence of the proposed insert
value, and go ahead only if NOT FOUND?
----- Original Message -----
From: "Francesco Casadei" <f_casadei(at)libero(dot)it>
To: <pgsql-general(at)postgresql(dot)org>
Sent: Monday, September 03, 2001 1:07 PM
Subject: [GENERAL] Catching errors inside a function
> I want to execute an INSERT query that may fail due to a primary key
constraint
> check. The primary key is on a field whose value is generated randomly by
> another C function.
> Is it possible to wrap the insert into a function that checks for failures
and
> retry the insert until success? Something like this:
>
> function blah
> {
> do {
> cod = generate code;
> execute insert with cod as primary key;
> } while (! errors);
> }
>
> I tried with SQL, PL/pgSQL and C functions but the backend aborts the
> transaction and stops execution of the function as soon as the error is
thrown.
> Is there a way to disable this behaviour?
>
> Thanks in advance for your help.
>
> Francesco Casadei
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tony Grant | 2001-09-04 17:05:45 | Re: [WAY OT] Re: PL/java? |
Previous Message | Robert J. Sanford, Jr. | 2001-09-04 16:35:57 | Re: PL/java? |