On Jul 16, 2007, at 15:55 , Jasbinder Singh Bali wrote:
I was wondering what would the function return if insert fails.
I want it to return 'success' upon a successful insert and
'failure' if
insert fails.
Depends on what you mean by "failed". Do you mean an error was
raised? Then you'll just get a normal error message. To catch this,
check the error trapping section of the PL/pgSQL documentation.
Do you mean nothing was inserted? If so, you won't catch this in your
above code. You can check the FOUND special variable after the INSERT
to see if anything was inserted and set your result message based on
that.
Would the following implementation work for that?
No. BEGIN/END blocks in PL/pgSQL are not equivalent to SQL BEGIN/
COMMIT transactions.
Michael Glaesemann
grzm seespotcode net