Re: Capturing return value of a function

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Jasbinder Singh Bali <jsbali(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Capturing return value of a function
Date: 2007-07-16 21:22:06
Message-ID: 2EBC0B3F-0103-4EC1-8994-16729CD5092C@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Stark 2007-07-16 21:23:03 Re: Capturing return value of a function
Previous Message Sébastien Boutté 2007-07-16 21:13:33 Re: pg_dump without blobs