Re: Returning a bool on DELETE in a proc.

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: KÖPFERL Robert <robert(dot)koepferl(at)sonorys(dot)at>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Returning a bool on DELETE in a proc.
Date: 2005-01-18 18:52:02
Message-ID: 20050118185202.GA39033@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Jan 18, 2005 at 05:04:58PM +0100, KÖPFERL Robert wrote:

> I'm currently writing a function which encapsulates a delete and should
> return a bool as indicator for success.

How do you define success? When the delete affects one or more rows?

> DELETE FROM "TariffDetails" WHERE "TariffId"=$1 and "BNumberPrefix"=$2;
> SELECT TRUE;
>
> but this makes me not happy.
> How can I distingruish wehter DELETE affected 0 or more rows and return that
> while DELETE is not capable of returning any value?

If you're using PL/pgSQL then see "Obtaining the Result Status" in
the "Basic Statements" section of the PL/pgSQL documentation.

> And is the whole function executed if the DELETE fails or will it stop
> bevore the select?

A PL/pgSQL function should exit immediately with an error if the
DELETE fails. But understand that PL/pgSQL's notion of a failure
might not match yours: trying to delete from a non-existent table
is a failure, but deleting zero rows from an existing table isn't.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joel Fradkin 2005-01-18 20:18:09 postgres stored procedures
Previous Message Keith Worthington 2005-01-18 18:46:23 Re: Returning a bool on DELETE in a proc.