postgresql - How does one report the line on which an error occured in Postgres/plpgsql? -
i have been using more or less in postgres emulate how, in sql server, have used try/catch blocks transactions can rolled in catch if error found:
do $$ begin [sql here] exception when others raise notice 'error in insert statement ---> % %', sqlerrm, sqlstate line; end; $$ language 'plpgsql';
is there way report line error occurred, "error_line()?
thanks in advance
on modern postgresql, can use get stacked diagnostics
statement. there not possibility linenumber, can call context, lineno included:
postgres=> $$ declare int default 0; _c text; begin begin perform 10/a; exception when others stacked diagnostics _c = pg_exception_context; raise notice 'context: >>%<<', _c; end; end; $$; notice: 00000: context: >>sql statement "select 10/a" pl/pgsql function inline_code_block line 7 @ perform<< location: exec_stmt_raise, pl_exec.c:3041
Comments
Post a Comment