Re: plperl and/or insert trigger problem

From: "Bart Degryse" <Bart(dot)Degryse(at)indicator(dot)be>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: plperl and/or insert trigger problem
Date: 2007-06-07 11:18:20
Message-ID: 4668059C.A3DD.0030.0@indicator.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Richard Huxton wrote:
> I'm no guru myself...
Don't underestimate yourself, after all you found the code where it goes wrong

> Looks OK to me, except you'll not get any error message on the last row
> - the insert will be called after the fetch.
I do get an error message on the last row (assuming that it caused an error of course)
There are [number of rows to fetch] + 1 fetches done by execute for fetch
As the POD says:
"The execute_for_fetch() method calls $fetch_tuple_sub ... until it returns a false value"
So I get the error caused by the last record when execute_for_fetch fetches again and
sees that there's nothing more to fetch.

>What happens if you change the code to take a copy of sth->errstr too:
Nothing. Same result. Which made me wonder why they take a copy of the
error code anyway. So I dropped that replacing
my $err = $sth->err;
push @$tuple_status, [ $err, $errstr_cache{$err} ||= $sth->errstr,
$sth->state ];
by
push @$tuple_status, [ $sth->err, $errstr_cache{$err} ||= $sth->errstr,
That gave me the same (but still unexpected) result.

Martijn van Oosterhout wrote:
> The reference to erstr_cache seems to infer that the code assumes there
> can be only one error string for any particular. Looking at the code I
> can't work out why that variable even exists.
And he was right! There lies the real problem. It seems to me like a (faulty)
way to try to return each different error message only once. But that wouldn't be
the behaviour as described in the POD.
So finally I replaced
my $err = $sth->err;
push @$tuple_status, [ $err, $errstr_cache{$err} ||= $sth->errstr,
$sth->state ];
by
push @$tuple_status, [ $sth->err, $sth->errstr, $sth->state ];
That gives the result I would expect when reading the POD

Thanks to both of you for solving this problem!
Bart

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Julian Scarfe 2007-06-07 12:15:34 last analyze time in 8.1?
Previous Message Johannes Konert 2007-06-07 10:57:18 Re: Suppress checking of chmod 700 on data-dir?