Re: TRIGGER BEFORE INSERT

From: Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com>
To: Alban Hertroys <alban(at)magproductions(dot)nl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: TRIGGER BEFORE INSERT
Date: 2007-01-11 18:26:32
Message-ID: 1168539992.4459.37.camel@zorro.isa-geek.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2007-01-11 at 15:10 +0100, Alban Hertroys wrote:
> Rafal Pietrak wrote:
> > Hi!
> >
> > I'm re-posting this message again in hope someone would have a look at
> > the case again. .. it's pending.
>
> You were given a solution; defer the foreign key constraint.

Well. I were, but probably I'm doing something wrong with 'deferring the
trigger'. When I put:

"SET CONSTRAINTS ALL DEFERRED ; "

*before* the UPDATE statement *within* the trigger function (just after
BEGIN statement there).

After doing so, notheing changes. I get the same ERROR. (all screenlogs
were included in previous posts, so I'll spare those here).

So may be "SET CONSTRAINTS .... DEFERRED " should be used somehow
differently? I've never had any use for that construct, may be I miss
something?

> Alternatively, you may want to re-think your trigger function so that it
> does things in the right order.

I cannot see *any* way to reorder the events in the triger function. The
function is short anough 'not to allow' :) for reordering - it just
makes an UPDATE to some other table (where it puts a reference to the
'fresh ROW') and stores the result of that update in the newly created
ROW.

And the problem is, that UPDATE puts a reference to the fresh ROW and
that the UPDATE statement does NOT SEE the 'freshly created ROW' - may
be this is not a case of 'too early constraint check', but rather a
problem of 'visibility' of data (new data) within a single transaction
(an UPDATE is launched within the trigger transaction - should see
already created ROW, shouldn't it?).

N.B. All the code that does fail is in my previous posts.

But as this is the 'second round' of my 'call for help' - I get an
impression, that there may actually not be a solution. Too bad.

-R

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2007-01-11 18:36:07 Re: TRIGGER BEFORE INSERT
Previous Message Russell Smith 2007-01-11 18:12:05 Re: Remove duplicate rows