Re: SQL design pattern for a delta trigger?

From: Colin Wetherbee <cww(at)denterprises(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL design pattern for a delta trigger?
Date: 2007-12-10 22:04:31
Message-ID: 475DB7EF.2020601@denterprises.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Vivek Khera wrote:
> On Dec 7, 2007, at 11:42 AM, Colin Wetherbee wrote:
>
>> You can do this with a conditional. Something like the following
>> should work.
>>
>> IF
>> NOT (a query matching your data returns rows)
>> THEN
>> INSERT (your new data)
>
> There exists a race condition here unless you've locked your tables.

Yes, clearly. In the context of the thread, I was assuming my algorithm
would be implemented as an atomic transaction.

For what it's worth, the real algorithm would be as follows. I hadn't
had enough coffee yet, and I forgot the UPDATE bit.

IF
(a query matching your old data returns rows)
THEN
UPDATE with your new data
ELSE
INSERT your new data

Colin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vivek Khera 2007-12-10 22:25:36 Re: Script to reset all sequence values in the a given DB?
Previous Message Scott Marlowe 2007-12-10 22:02:19 Re: slony question