From ea217e9c14a5756b49b702e3b8919425169d15b9 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 5 Mar 2018 22:12:31 -0500 Subject: [PATCH] update import function to trap all error at the end --- deploy/ubm_schema.sql | 37 ++++++++++++++++++------------------- functions/srce_import.sql | 37 ++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/deploy/ubm_schema.sql b/deploy/ubm_schema.sql index 8b4d588..bc31963 100644 --- a/deploy/ubm_schema.sql +++ b/deploy/ubm_schema.sql @@ -484,24 +484,7 @@ BEGIN --RAISE NOTICE '%', _t; - BEGIN - EXECUTE _t; - EXCEPTION WHEN OTHERS THEN - GET STACKED DIAGNOSTICS - _MESSAGE_TEXT = MESSAGE_TEXT, - _PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL, - _PG_EXCEPTION_HINT = PG_EXCEPTION_HINT; - _message:= - ($$ - { - "status":"fail", - "message":"error importing data" - } - $$::jsonb) - ||jsonb_build_object('message_text',_MESSAGE_TEXT) - ||jsonb_build_object('pg_exception_detail',_PG_EXCEPTION_DETAIL); - return _message; - END; + EXECUTE _t; WITH @@ -646,7 +629,23 @@ BEGIN )||jsonb_build_object('details',_log_info); RETURN _message; -END + +EXCEPTION WHEN OTHERS THEN + GET STACKED DIAGNOSTICS + _MESSAGE_TEXT = MESSAGE_TEXT, + _PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL, + _PG_EXCEPTION_HINT = PG_EXCEPTION_HINT; + _message:= + ($$ + { + "status":"fail", + "message":"error importing data" + } + $$::jsonb) + ||jsonb_build_object('message_text',_MESSAGE_TEXT) + ||jsonb_build_object('pg_exception_detail',_PG_EXCEPTION_DETAIL); + return _message; +END; $_$; diff --git a/functions/srce_import.sql b/functions/srce_import.sql index 657161f..9cb2a85 100644 --- a/functions/srce_import.sql +++ b/functions/srce_import.sql @@ -89,24 +89,7 @@ BEGIN --RAISE NOTICE '%', _t; - BEGIN - EXECUTE _t; - EXCEPTION WHEN OTHERS THEN - GET STACKED DIAGNOSTICS - _MESSAGE_TEXT = MESSAGE_TEXT, - _PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL, - _PG_EXCEPTION_HINT = PG_EXCEPTION_HINT; - _message:= - ($$ - { - "status":"fail", - "message":"error importing data" - } - $$::jsonb) - ||jsonb_build_object('message_text',_MESSAGE_TEXT) - ||jsonb_build_object('pg_exception_detail',_PG_EXCEPTION_DETAIL); - return _message; - END; + EXECUTE _t; WITH @@ -251,7 +234,23 @@ BEGIN )||jsonb_build_object('details',_log_info); RETURN _message; -END + +EXCEPTION WHEN OTHERS THEN + GET STACKED DIAGNOSTICS + _MESSAGE_TEXT = MESSAGE_TEXT, + _PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL, + _PG_EXCEPTION_HINT = PG_EXCEPTION_HINT; + _message:= + ($$ + { + "status":"fail", + "message":"error importing data" + } + $$::jsonb) + ||jsonb_build_object('message_text',_MESSAGE_TEXT) + ||jsonb_build_object('pg_exception_detail',_PG_EXCEPTION_DETAIL); + return _message; +END; $f$ LANGUAGE plpgsql