Skip site navigation (1) Skip section navigation (2)

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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: 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-27 15:36:45
Message-ID: 23790.1254065805@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Sat, Sep 26, 2009 at 12:35 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Well, yeah. That's exactly how it's documented to work: an ON INSERT
>> rule is executed after the INSERT proper.

> I'm confused.  DO INSTEAD doesn't mean DO INSTEAD?

It does.  What it doesn't mean is "IF ... THEN ... ELSE ...".
The OP's rule actually works more like

	if (!(EXISTS ...))
		INSERT ...

	if ((EXISTS ...))
		UPDATE ...

>> You could maybe make this work with a BEFORE INSERT trigger.

> I'm not sure you can make it reliable though.

Concurrent inserts make things even more interesting, yes; but the rule
had no hope of handling that anyway.

			regards, tom lane

In response to

Responses

pgsql-bugs by date

Next:From: Robert HaasDate: 2009-09-27 18:36:45
Subject: Re: BUG #5081: ON INSERT rule does not work correctly
Previous:From: Robert HaasDate: 2009-09-27 13:46:03
Subject: Re: BUG #5081: ON INSERT rule does not work correctly

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group