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 1FFE33A2169 for ; Tue, 18 Jan 2005 18:52:11 +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 55788-04 for ; Tue, 18 Jan 2005 18:52:06 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 0D2B63A217B for ; Tue, 18 Jan 2005 18:52:06 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id j0IIq2RZ004070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Jan 2005 11:52:05 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id j0IIq2QC039110; Tue, 18 Jan 2005 11:52:02 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id j0IIq2CF039109; Tue, 18 Jan 2005 11:52:02 -0700 (MST) (envelope-from mfuhr) Date: Tue, 18 Jan 2005 11:52:02 -0700 From: Michael Fuhr To: =?iso-8859-1?Q?K=D6PFERL?= Robert Cc: pgsql-sql@postgresql.org Subject: Re: Returning a bool on DELETE in a proc. Message-ID: <20050118185202.GA39033@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/134 X-Sequence-Number: 19922 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/