-- Test that the system reports a sensible error when -- the executed sql raises a data_exception BEGIN; -- run_isok_queries() expects an expression that returns results -- from a table. So create a function that does that, but instead -- raises the error we want to test. CREATE FUNCTION test_func() RETURNS TABLE (c1 TEXT, c2 TEXT, c3 TEXT) LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION data_exception USING MESSAGE = 'Test of data_exception'; END; $$; -- Update the query to raise the error UPDATE isok_queries SET query = $$SELECT * FROM test_func();$$ WHERE iqname = 'query1'; -- Run to see trapped error SELECT irid, iqname, qr_id, qr_message, qr_extra FROM run_isok_queries($$VALUES ('query1');$$) ORDER BY irid; ERROR: run_isok_queries: Error executing stored ISOK_QUERIES.Query DETAIL: Problem in the saved query with IQName = (query1): The error is: Test of data_exception The query is: SELECT * FROM test_func(); Additional diagnostic information: PL/pgSQL function test_func() line 3 at RAISE PL/pgSQL function run_isok_queries(text) line 182 at FOR over EXECUTE statement CONTEXT: PL/pgSQL function run_isok_queries(text) line 396 at RAISE ROLLBACK;