From: A. Kulikov <a.kulikov@gmail.com>
To: pgsql-sql@postgresql.org
Subject: User Defined Functions Errors
Date: Mon, 18 Apr 2005 22:32:26 +0400
Message-ID: <fc63e1af05041811327a8b3061@mail.gmail.com> (raw)
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/
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: a.kulikov@gmail.com
Subject: Re: User Defined Functions Errors
In-Reply-To: <fc63e1af05041811327a8b3061@mail.gmail.com>
* 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