Re: SQL design pattern for a delta trigger?

From: Vivek Khera <khera(at)kcilink(dot)com>
To: Colin Wetherbee <cww(at)denterprises(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL design pattern for a delta trigger?
Date: 2007-12-10 22:27:14
Message-ID: FF08171D-0F1F-4AA7-91F4-ACE7D345D591@kcilink.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Dec 10, 2007, at 5:04 PM, Colin Wetherbee wrote:

> 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

Still exists race condition. Your race comes from testing existence,
then creating/modifying data afterwards. You need to make the test/
set atomic else you have race.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-12-10 22:29:44 Re: partitioned table query question
Previous Message Vivek Khera 2007-12-10 22:25:36 Re: Script to reset all sequence values in the a given DB?