Wednesday, July 3, 2013

good news for plpgsql developers - enhanced diagnostics fiedls will be available in 9.3

Noah Misch commited my patch, that allows a access to diagnostics fields from PLpgSQL. It can be used for structured custom exception (these fields are accessible on client side).

create or replace function stacked_diagnostics_test() returns void as $$
declare _column_name text;
        _constraint_name text;
        _datatype_name text;
        _table_name text;
        _schema_name text;
  raise exception using
    column = '**some column name**',
    constraint = '**some constraint name**',
    datatype = '**some datatype name**',
    table = '**some table name**',
    schema = '**some schema name**';
exception when others then
  get stacked diagnostics
        _column_name = column_name,
        _constraint_name = constraint_name,
        _datatype_name = pg_datatype_name,
        _table_name = table_name,
        _schema_name = schema_name;
  raise notice 'column %, constraint %, type %, table %, schema %',
    _column_name, _constraint_name, _datatype_name, _table_name, _schema_name;
$$ language plpgsql;

select stacked_diagnostics_test();

NOTICE:  column **some column name**, constraint **some constraint name**, type **some datatype name**, table **some table name**, schema **some schema name**
(1 row)


Post a Comment

Subscribe to Post Comments [Atom]

<< Home