Re: Capturing return value of a function - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: Capturing return value of a function
Date
Msg-id 2EBC0B3F-0103-4EC1-8994-16729CD5092C@seespotcode.net
Whole thread Raw
In response to Capturing return value of a function  ("Jasbinder Singh Bali" <jsbali@gmail.com>)
List pgsql-general
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



pgsql-general by date:

Previous
From: "Sébastien Boutté"
Date:
Subject: Re: pg_dump without blobs
Next
From: Gregory Stark
Date:
Subject: Re: Capturing return value of a function