Re: Capturing return value of a function

From: Gregory Stark <stark(at)enterprisedb(dot)com>
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:23:03
Message-ID: 87d4ysvya0.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


"Jasbinder Singh Bali" <jsbali(at)gmail(dot)com> writes:

> I was wondering what would the function return if insert fails.

It would abort immediately and abort your transaction as well unless something
higher up catches the error.

> I want it to return 'success' upon a successful insert and 'failure' if
> insert fails.

You need an EXCEPT WHEN clause, see:

http://www.postgresql.org/docs/8.2/interactive/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message George Weaver 2007-07-16 21:27:49 Re: Capturing return value of a function
Previous Message Michael Glaesemann 2007-07-16 21:22:06 Re: Capturing return value of a function