Re: proposal 9.4 plpgsql: allows access to call stack from GET DIAGNOSTICS statement - Mailing list pgsql-hackers

From Jim Nasby
Subject Re: proposal 9.4 plpgsql: allows access to call stack from GET DIAGNOSTICS statement
Date
Msg-id 5137E547.40405@nasby.net
Whole thread Raw
In response to proposal 9.4 plpgsql: allows access to call stack from GET DIAGNOSTICS statement  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
On 2/2/13 3:23 AM, Pavel Stehule wrote:
> Hello
>
> I propose enhancing GET DIAGNOSTICS statement about new field
> PG_CONTEXT. It is similar to GET STACKED DIAGNOSTICS'
> PG_EXCEPTION_CONTEXT.
>
> Motivation for this proposal is possibility to get  call stack for
> debugging without raising exception.
>
> This code is based on cleaned code from Orafce, where is used four
> years without any error reports.
>
> CREATE OR REPLACE FUNCTION public."inner"(integer)
>   RETURNS integer
>   LANGUAGE plpgsql
> AS $function$
> declare _context text;
> begin
>    get diagnostics _context = pg_context;
>    raise notice '***%***', _context;
>    return 2 * $1;
> end;
> $function$
>
> postgres=# select outer_outer(10);
> NOTICE:  ***PL/pgSQL function "inner"(integer) line 4 at GET DIAGNOSTICS
> PL/pgSQL function "outer"(integer) line 3 at RETURN
> PL/pgSQL function outer_outer(integer) line 3 at RETURN***
> CONTEXT:  PL/pgSQL function "outer"(integer) line 3 at RETURN
> PL/pgSQL function outer_outer(integer) line 3 at RETURN

That could *really* stand for some indentation in the output instead of the *** business. But other than that, this
definitelyseems useful. I had no idea _context was even an option... :/
 



pgsql-hackers by date:

Previous
From: Jim Nasby
Date:
Subject: Re: Using indexes for partial index builds
Next
From: Robert Haas
Date:
Subject: Re: [v9.3] OAT_POST_ALTER object access hooks