From: | Alvaro Herrera <alvherre(at)atentus(dot)com> |
---|---|
To: | Francesco Casadei <f_casadei(at)libero(dot)it> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Catching errors inside a function |
Date: | 2001-09-03 19:47:35 |
Message-ID: | Pine.LNX.4.33L2.0109031545050.31230-100000@aguila.protecne.cl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, 3 Sep 2001, Francesco Casadei wrote:
> 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.
Wouldn't it be easier if you just used a sequence to generate the
primary key, if you just want uniqueness?
> 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);
> }
Any error will abort the transaction. You can't avoid this. Perhaps you
can try inserting the value outside the transaction, and then open it to
do whatever you want with the value inserted.
> Is there a way to disable this behaviour?
No.
--
Alvaro Herrera (<alvherre[(at)]atentus(dot)com>)
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2001-09-03 19:50:29 | Re: European date format option |
Previous Message | Alex Knight | 2001-09-03 19:37:16 | Re: [WAY OT] Re: PL/java? |