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 8536B53223 for ; Mon, 18 Apr 2005 15:32:39 -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 29280-02 for ; Mon, 18 Apr 2005 18:32:28 +0000 (GMT) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.196]) by svr1.postgresql.org (Postfix) with ESMTP id 3435452A6A for ; Mon, 18 Apr 2005 15:32:24 -0300 (ADT) Received: by rproxy.gmail.com with SMTP id j1so1049509rnf for ; Mon, 18 Apr 2005 11:32:26 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=RvoC88slfWE+WyvkG3ivTEDdjdu1COiLYjkIYnIstC2nBb9NESZZyobt+7codH1lqud0uonmGbaIa+FfPbsSmFGtGss64aidYDh01c+LRLlGDCyZw7W5ZaImOFYYehickEhsBf4lWbnE8KEa3XNXtSIDaSNhoOOeQucbDLdzi3A= Received: by 10.38.96.65 with SMTP id t65mr6132581rnb; Mon, 18 Apr 2005 11:32:26 -0700 (PDT) Received: by 10.38.209.59 with HTTP; Mon, 18 Apr 2005 11:32:26 -0700 (PDT) Message-ID: Date: Mon, 18 Apr 2005 22:32:26 +0400 From: "A. Kulikov" Reply-To: "A. Kulikov" To: pgsql-sql@postgresql.org Subject: User Defined Functions Errors Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.408 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, RCVD_BY_IP, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200504/254 X-Sequence-Number: 21147 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;=20 mright INTEGER; BEGIN -- Check if the desired node exists SELECT lft, rgt FROM structure WHERE id =3D $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 >=3D mleft AND rgt <=3D mright; -- Close the gap UPDATE structure SET rgt =3D rgt - (mright - mleft + 1) WHERE rgt > mright; UPDATE structure SET lft =3D 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 --=20 The mind is essential -- http://essentialmind.com/