Search Postgresql Archives

Re: Dynamic use of RAISE with USING to generate and catch non-hardcoded custom exceptions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



mike davis <mike.davis65@xxxxxxxxxxx> writes:
> I'm trying to get dynamic version of the RAISE command working so
> that I can use a table of custom application error messages and codes
> for use by all developed plpgsql functions.

This works for me:

DO $$
DECLARE
  v_msg TEXT := 'SOMETHING IS WRONG';
  v_sqlstate TEXT := 'E0001';
BEGIN
  RAISE EXCEPTION USING message = v_msg, errcode = v_sqlstate;
EXCEPTION
  WHEN SQLSTATE 'E0001' THEN
     RAISE NOTICE '%','Error E0001 raised - going to do something about it';
  WHEN OTHERS THEN
     RAISE NOTICE 'OTHER ERRORS: %,%', sqlstate,sqlerrm;
END$$;

NOTICE:  Error E0001 raised - going to do something about it

Or you could do

  RAISE EXCEPTION SQLSTATE v_sqlstate USING message = v_msg;

			regards, tom lane


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux