Re: BUG #5081: ON INSERT rule does not work correctly - Mailing list pgsql-bugs

From Jacques Caron
Subject Re: BUG #5081: ON INSERT rule does not work correctly
Date
Msg-id 20090928141310.E384F35A28BB@zeus.directinfos.com
Whole thread Raw
In response to BUG #5081: ON INSERT rule does not work correctly  ("Stefan" <sb@drbott.de>)
Responses Re: BUG #5081: ON INSERT rule does not work correctly  (Robert Haas <robertmhaas@gmail.com>)
List 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@postgresql.org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-bugs

pgsql-bugs by date:

Previous
From: Stefan Bähring
Date:
Subject: Re: BUG #5081: ON INSERT rule does not work correctly
Next
From: Heikki Linnakangas
Date:
Subject: Re: BUG #5084: Query gives different number of rows depending on ORDER BY