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

2009-09-28 Thread Robert Haas
On Mon, Sep 28, 2009 at 10:12 AM, Jacques Caron wrote: > 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. That seems about right.

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

2009-09-28 Thread Jacques Caron
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

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

2009-09-28 Thread Stefan Bähring
--On 27. September 2009 14:36:45 -0400 Robert Haas wrote: On Sun, Sep 27, 2009 at 11:36 AM, Tom Lane wrote: Robert Haas writes: On Sat, Sep 26, 2009 at 12:35 PM, Tom Lane wrote: Well, yeah.  That's exactly how it's documented to work: an ON INSERT rule is executed after the INSERT pro

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

2009-09-27 Thread Robert Haas
On Sun, Sep 27, 2009 at 11:36 AM, Tom Lane wrote: > Robert Haas writes: >> On Sat, Sep 26, 2009 at 12:35 PM, Tom Lane 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 INST

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

2009-09-27 Thread Tom Lane
Robert Haas writes: > On Sat, Sep 26, 2009 at 12:35 PM, Tom Lane 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 ... E

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

2009-09-27 Thread Robert Haas
On Sat, Sep 26, 2009 at 12:35 PM, Tom Lane wrote: > "Stefan" writes: >> The problem is that if it is no record in the table, it seems that first the >> INSERT command is issued and after that the UPDATE command is issued, too. > > Well, yeah.  That's exactly how it's documented to work: an ON INS

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

2009-09-26 Thread Tom Lane
"Stefan" writes: > The problem is that if it is no record in the table, it seems that first the > INSERT command is issued and after that the UPDATE command is issued, too. Well, yeah. That's exactly how it's documented to work: an ON INSERT rule is executed after the INSERT proper. You could m