Re: BUG #5081: ON INSERT rule does not work correctly

From: Jacques Caron <jc(at)oxado(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>,Stefan <sb(at)drbott(dot)de>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5081: ON INSERT rule does not work correctly
Date: 2009-09-28 14:12:38
Message-ID: 20090928141310.E384F35A28BB@zeus.directinfos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

You can use a trigger before insert and a pl/pgsql function that goes:

BEGIN
UPDATE table SET ... WHERE pk=NEW.pk
IF FOUND THEN
RETURN NULL;
ELSE
RETURN NEW;
END IF;
END;

Jacques.

At 19:36 27/09/2009, Robert Haas wrote:
>Sometimes when I've needed to do this I've written a PL/pgsql function
>that tries the insert and then fails over to an UPDATE if the INSERT
>fails due to a unique-violation. I'm not sure that's 100% robust
>either, though, unless using serializable mode.
>
>...Robert
>
>--
>Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-bugs

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Heikki Linnakangas 2009-09-28 15:10:07 Re: BUG #5084: Query gives different number of rows depending on ORDER BY
Previous Message tomas 2009-09-28 11:42:47 Re: PROBLEMA AL INSTALAR POSTSGRESQL