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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -