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 93FA6539AB for ; Tue, 19 Apr 2005 04:24:02 -0300 (ADT) 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 75698-08 for ; Tue, 19 Apr 2005 07:23:52 +0000 (GMT) Received: from mx-00.sil.at (mx-00.sil.at [62.116.68.196]) by svr1.postgresql.org (Postfix) with ESMTP id CA22A5399E for ; Tue, 19 Apr 2005 04:23:50 -0300 (ADT) Received: (qmail-ldap/ctrl 75874 invoked from network); 19 Apr 2005 07:23:49 -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 Apr 2005 07:23:49 -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 j3J7Nn108726; Tue, 19 Apr 2005 09:23:49 +0200 (MEST) Received: by neptun.sonorys.at with Internet Mail Service (5.5.2653.19) id <2JD5W2SK>; Tue, 19 Apr 2005 09:23:49 +0200 Message-ID: From: =?ISO-8859-1?Q?K=D6PFERL_Robert?= To: "'A. Kulikov'" Cc: pgsql-sql@postgresql.org Subject: Re: User Defined Functions Errors Date: Tue, 19 Apr 2005 09:23:46 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="ISO-8859-1" X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200504/274 X-Sequence-Number: 21167 Have a try with RAISE NOTE or RAISE EXCEPTION keep in mind that exceptions should be exceptional. So a good idea of whether to use them is to ask 'Do I expect such error' or 'is an explicit error useful for the caller'. I'ts often better to just return an empty relation |-----Original Message----- |From: A. Kulikov [mailto:a.kulikov@gmail.com] |Sent: Montag, 18. April 2005 20:32 |To: pgsql-sql@postgresql.org |Subject: [SQL] User Defined Functions Errors | | |How to I return an error from inside a user defined function? For |example the following: | |CREATE or REPLACE FUNCTION drop_node (integer) RETURNS text |AS ' | |DECLARE | |mleft INTEGER; |mright INTEGER; | |BEGIN | |-- Check if the desired node exists |SELECT lft, rgt FROM structure WHERE id = $1 INTO mleft, mright; | |IF mleft IS NULL THEN | RETURN ''No entry found with an id of ''||$2; |END IF; | |-- Drop the node and its subtree |DELETE FROM structure WHERE lft >= mleft AND rgt <= mright; | |-- Close the gap |UPDATE structure SET rgt = rgt - (mright - mleft + 1) WHERE |rgt > mright; |UPDATE structure SET lft = lft - (mright - mleft + 1) WHERE |lft > mleft; | |RETURN ''ok''; | |END; |' |LANGUAGE 'plpgsql'; | |Should be terminated with an error @ RETURN "No Entry found"; instead |of returning the error text. | |best regards and thanks, | |Alex |-- |The mind is essential -- http://essentialmind.com/ | |---------------------------(end of |broadcast)--------------------------- |TIP 4: Don't 'kill -9' the postmaster |