text: load 'plpgsql';
  load 'plpgsql_check';
  set client_min_messages to notice;
  
  set plpgsql_check.mode = 'every_start';
  
  create type _exception_type as (
    state text,
    message text,
    detail text);
  
  create or replace function f1()
  returns void as $$
  declare
    _exception record;
  begin
    _exception := NULL::_exception_type;
  exception when others then
    get stacked diagnostics
          _exception.state = RETURNED_SQLSTATE,
          _exception.message = MESSAGE_TEXT,
          _exception.detail = PG_EXCEPTION_DETAIL,
          _exception.hint = PG_EXCEPTION_HINT;
  end;
  $$ language plpgsql;
  
  select f1();
  
  drop function f1();
  drop type _exception_type;
  