From: | "A(dot) Kulikov" <a(dot)kulikov(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | User Defined Functions Errors |
Date: | 2005-04-18 18:32:26 |
Message-ID: | fc63e1af05041811327a8b3061@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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/
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2005-04-18 19:07:53 | Re: User Defined Functions Errors |
Previous Message | Tom Lane | 2005-04-18 17:26:49 | Re: 'Select INTO" in Execute (dynamic query ) |