pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: KÖPFERL Robert <robert.koepferl@sonorys.at>
Cc: pgsql-sql@postgresql.org
Subject: Re: Returning a bool on DELETE in a proc.
Date: Wed, 19 Jan 2005 11:24:26 +0100
Message-ID: <ED4E30DD9C43D5118DFB00508BBBA76EB1656B@neptun.sonorys.at> (raw)

Thanks, but that was not what I was looking for.

Seems that I forgot to mention that this function is intended to be written
in SQL, not in PL/SQL. For the second one I already picked it off the
fascinating* doc (as Keith did) that GET DIAGONSTIC is the right thing.

So what variable/function is the correct SQL-equivalent to ROW_COUNT and can
it be used in the following statement ?
like DELETE...; SELECT (ROW_COUNT<>0); to return a bool value?

Or would you really suggest to change the fct's type to void?


*The doc is fascinating, because it is rather short in terms of PL/pgSQL but
if you are looking for something you can find it in some example or
mentioned in a sentence somweheewere

> -----Original Message-----
> From: Michael Fuhr [mailto:mike@fuhr.org]
> Sent: Dienstag, 18. Jänner 2005 19:52
> To: KÖPFERL Robert
> Cc: pgsql-sql@postgresql.org
> Subject: Re: [SQL] Returning a bool on DELETE in a proc.
> 
> 
> 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/
> 



view thread (8+ messages)  latest in thread

Message-ID: <ED4E30DD9C43D5118DFB00508BBBA76EB1656B@neptun.sonorys.at>
Permalink:  ../ED4E30DD9C43D5118DFB00508BBBA76EB1656B@neptun.sonorys.at/
Also on:    postgresql.org/message-id/ED4E30DD9C43D5118DFB00508BBBA76EB1656B@neptun.sonorys.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: robert.koepferl@sonorys.at
  Subject: Re: Returning a bool on DELETE in a proc.
  In-Reply-To: <ED4E30DD9C43D5118DFB00508BBBA76EB1656B@neptun.sonorys.at>
  References: <ED4E30DD9C43D5118DFB00508BBBA76EB1656B@neptun.sonorys.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox