dbTalk Databases Forums  

Re: [BUGS] plpgsql error handling bug

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] plpgsql error handling bug in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: [BUGS] plpgsql error handling bug - 09-05-2004 , 12:19 PM







On Sun, 5 Sep 2004 Ivan-Sun1 (AT) mail (DOT) ru wrote:

Quote:
I found a bug in the behaviour of plpgsql error handling system
while trying to handle foreign key violation exception.

When this error occured, control doesn't jump to exception handling block.
It moves to the next statement instead. When control leaves the
function exception is occured. So it's impossible to handle this kind of
exception.
IIRC that's because the check is not happening until after the function is
finished (at the end of the user sent statement). If so, then yes,
currently there'd be no way to handle the exception.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] plpgsql error handling bug - 09-05-2004 , 12:24 PM






Ivan-Sun1 (AT) mail (DOT) ru writes:
Quote:
I found a bug in the behaviour of plpgsql error handling system
while trying to handle foreign key violation exception.
This is not a bug in the exception system.

The problem is that FK constraints are enforced by triggers that do not
fire until the end of the outer statement (that is, the SELECT that
calls the plpgsql function). So by the time the constraint error is
raised, we have long since exited the exception structure.

There has been some talk of changing trigger firing rules to make this
sort of thing behave more intuitively inside functions, but it hasn't
happened yet.

Maybe we should think about doing something about this for 8.0? It's a
larger behavioral change than I like to think about for post-beta, but
(a) the exception mechanism's usefulness is certainly going to be
severely limited if it can't catch FK errors; (b) 8.0 seems like a
more appropriate time to introduce backwards-incompatibilities than
future 8.x releases.

I would imagine that the right thing would be to fire pending
non-deferred triggers at the end of every SPI_exec/execp, not only at
the outer loop. Are there other places that it would be needed in
addition, or instead?

Comments?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #3  
Old   
Gaetano Mendola
 
Posts: n/a

Default Re: [BUGS] plpgsql error handling bug - 09-05-2004 , 04:06 PM



Tom Lane wrote:

Quote:
Ivan-Sun1 (AT) mail (DOT) ru writes:

I found a bug in the behaviour of plpgsql error handling system
while trying to handle foreign key violation exception.


This is not a bug in the exception system.

The problem is that FK constraints are enforced by triggers that do not
fire until the end of the outer statement (that is, the SELECT that
calls the plpgsql function). So by the time the constraint error is
raised, we have long since exited the exception structure.

There has been some talk of changing trigger firing rules to make this
sort of thing behave more intuitively inside functions, but it hasn't
happened yet.

Maybe we should think about doing something about this for 8.0? It's a
larger behavioral change than I like to think about for post-beta, but
(a) the exception mechanism's usefulness is certainly going to be
severely limited if it can't catch FK errors; (b) 8.0 seems like a
more appropriate time to introduce backwards-incompatibilities than
future 8.x releases.
Considering also that if you fix the BUG #1231 then 8.0 have already some
backwards-incompatibilities so one more is mitigated by the other one.



Regards
Gaetano Mendola




---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.