Re: INSERT WHERE NOT EXISTS

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: techlist(at)voyager(dot)phys(dot)utk(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: INSERT WHERE NOT EXISTS
Date: 2003-06-25 20:25:54
Message-ID: 3EFA0552.8060905@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Reuben D. Budiardja wrote:

>>Reuben must be prepared for unique key violation, I'm afraid. And,
>>despite the optimism in the link, we still don't have savepoints. :-(
>
> Interesting reading of the archive. In my particular case here, I don't have
> to worry too much about the race thing. But the inherent problem is still
> there.
>
> Where can I read / learn more about the so-called "savepoints"? This is the
> first time I've heard it. Granted, I've only been using postgresql recently.

Here's a link to Oracle's implementation:

http://www.engin.umich.edu/caen/wls/software/oracle/server.901/a90125/statements_102.htm#2091263

If PostgreSQL had SAVEPOINTs or even nested transactions, one could
handle a unique key violation without having to resubmit the whole
transaction. Eg:

BEGIN; <- Outer Tx

.. do a lot of work ..

LOOP:

status = ABORTED

WHILE (status == ABORTED) {
BEGIN; <- Nested Tx
UPDATE foo SET val = 1 WHERE key = 0;
IF zero rows updated {
INSERT INTO foo...
^- Causes unique key violation, but only Nested Tx in ABORT state
}
status = TX state;
END;
}

END;

I believe there are hackers working on nested transactions for 7.5?

Mike Mascari
mascarm(at)mascari(dot)com

>
> Thanks.
> RDB
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Pflug 2003-06-25 20:43:06 Re: [GENERAL] Physical Database Configuration
Previous Message Mike Mascari 2003-06-25 20:23:41 Re: INSERT WHERE NOT EXISTS