Re: trappable warnings, dynamic change of minimal level for PG_RE_THROW

Lists: pgsql-hackers
From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: neilc(at)samurai(dot)com
Subject: trappable warnings, dynamic change of minimal level for PG_RE_THROW
Date: 2006-12-05 19:53:55
Message-ID: BAY20-F17C55ABA357DBA09593521F9DE0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

SQL/PSM concept of condition's handlers suppouses so all signals (all levels
of exception's) are trappable. Common construct is:
begin
declare finish boolean default false;
declare continue handler for sqlwarning set finish = true;
open cursor
while not finish do
fetch from cursor
end while;
close cursor;
end;

Every compound statement in sql/psm has default empty continue handler for
success, warning and not found signal's.

Current code in errfinish (elog.c) throw signal only when level is error.

if (elevel == ERROR)
{
...
PG_RE_THROW();
}

I have to dynamicly change this level for all sql/psm block. Can be solution
using of global variable? Like error_context_stack?

hypotetic code from pl/plpgsql/src/pl_exec.c

static int
exec_stmt_block(PLpgPSM_execstate *estate, PLpgPSM_stmt_block *block)
{
int current_min_level = error_min_level; /* global variable from
elog.c */

min_level = INFO;
....
PG_TRY()
....
PG_CATCH()
....
PG_END_TRY()

error_min_level = current_min_level;
}

Is it safe? Any ideas?

Regards
Pavel Stehule

_________________________________________________________________
Chcete sdilet sve obrazky a hudbu s prateli? http://messenger.msn.cz/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, neilc(at)samurai(dot)com
Subject: Re: trappable warnings, dynamic change of minimal level for PG_RE_THROW
Date: 2006-12-05 20:18:38
Message-ID: 10639.1165349918@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> Current code in errfinish (elog.c) throw signal only when level is error.
> I have to dynamicly change this level for all sql/psm block. Can be solution
> using of global variable? Like error_context_stack?

You certainly would not want to use TRY/CATCH to handle warnings,
because that way would cause the statement to be aborted before
completion, quite possibly without essential cleanup. Another problem
is that the conditions you are interested don't produce elog messages at
all (and shouldn't). You need a new mechanism for this, likely.

regards, tom lane