X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 721003A3D61 for ; Wed, 19 Jan 2005 10:24:39 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63349-04 for ; Wed, 19 Jan 2005 10:24:27 +0000 (GMT) Received: from mx-00.sil.at (mx-00.sil.at [62.116.68.196]) by svr1.postgresql.org (Postfix) with ESMTP id A53413A3D59 for ; Wed, 19 Jan 2005 10:24:27 +0000 (GMT) Received: (qmail-ldap/ctrl 99901 invoked from network); 19 Jan 2005 10:24:25 -0000 Received: from unknown (HELO jupiter.sonorys.at) ([213.235.243.42]) (envelope-sender ) by mx-00.sil.at (qmail-ldap-1.03) with SMTP for ; 19 Jan 2005 10:24:25 -0000 Received: from neptun.sonorys.at (neptun.sonorys.at [172.24.1.17]) by jupiter.sonorys.at (8.11.7+Sun/8.11.7) with ESMTP id j0JAOds15491 for ; Wed, 19 Jan 2005 11:24:39 +0100 (MET) Received: by neptun.sonorys.at with Internet Mail Service (5.5.2653.19) id ; Wed, 19 Jan 2005 11:24:27 +0100 Message-ID: From: =?ISO-8859-1?Q?K=D6PFERL_Robert?= To: Cc: pgsql-sql@postgresql.org Subject: Re: Returning a bool on DELETE in a proc. Date: Wed, 19 Jan 2005 11:24:26 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200501/141 X-Sequence-Number: 19929 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=E4nner 2005 19:52 > To: K=D6PFERL Robert > Cc: pgsql-sql@postgresql.org > Subject: Re: [SQL] Returning a bool on DELETE in a proc. >=20 >=20 > On Tue, Jan 18, 2005 at 05:04:58PM +0100, K=D6PFERL Robert wrote: >=20 > > I'm currently writing a function which encapsulates a=20 > delete and should > > return a bool as indicator for success. >=20 > How do you define success? When the delete affects one or more rows? >=20 > > DELETE FROM "TariffDetails" WHERE "TariffId"=3D$1 and=20 > "BNumberPrefix"=3D$2; > > SELECT TRUE; > >=20 > > but this makes me not happy. > > How can I distingruish wehter DELETE affected 0 or more=20 > rows and return that > > while DELETE is not capable of returning any value? >=20 > If you're using PL/pgSQL then see "Obtaining the Result Status" in > the "Basic Statements" section of the PL/pgSQL documentation. >=20 > > And is the whole function executed if the DELETE fails or=20 > will it stop > > bevore the select? >=20 > 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. >=20 > --=20 > Michael Fuhr > http://www.fuhr.org/~mfuhr/ >=20