Any way to handle exceptions in PL/pgSQL ?

From: "Jorg Janke" <jorg(dot)janke(at)compiere(dot)org>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Any way to handle exceptions in PL/pgSQL ?
Date: 2002-06-01 04:11:44
Message-ID: 6E2C6F49B3E09548A38EDCAD31C4182F04DDA0@MAIN.compiere.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Is there any way to handle failed queries in PL/pgSQL?

<< I am aware that the example can be re-worded in a single query; This
is a question more on how to do the 'procedural' part >>

Example:
1st query
if OK, return result
2ne query
if OK, return result
return error message

Is it correct, that if a function fails, it returns null ??

-- Function: message_get(varchar)
CREATE FUNCTION message_get(varchar) RETURNS varchar AS '
DECLARE
p_key ALIAS FOR $1;
v_RetValue Message.MsgText%TYPE;
BEGIN
SELECT MsgText INTO v_RetValue
FROM User_Message
WHERE Value = p_Value;
-- if ok ??
RETURN v_RetValue;

SELECT Text INTO v_RetValue
FROM Sys_Message
WHERE Value = p_Value;
-- if ok ??
RETURN v_RetValue;

RETURN 'nothing found';
END;
' LANGUAGE 'plpgsql';

Cheers,

Jorg Janke (203) 445-9503 http://www.compiere.org
Smart ERP & CRM Business Solution for Distribution and Service globally
------------------------------------------------------------------------
General questions/issues: http://sourceforge.net/forum/?group_id=29057
Support via: http://sourceforge.net/tracker/?group_id=29057&atid=410216
------------------------------------------------------------------------

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message PG Explorer 2002-06-01 10:01:58 Re: Any way to handle exceptions in PL/pgSQL ?
Previous Message Ricardo Javier Aranibar León 2002-06-01 00:32:00 problem with sql