Обсуждение: How to handle error message in PG_CATCH

Поиск
Список
Период
Сортировка

How to handle error message in PG_CATCH

От
Zdenek Kotala
Дата:
I'm working on implementing pg_check functions. Because I want to test 
whole table I need catch a error and handle it myself. I use following 
construct:



PG_TRY();
{...ereport(ERROR, (errmsg("Error test")));...
}
PG_CATCH();
{errcontext("Context error");        EmitErrorReport();        FlushErrorState();
}
PG_END_TRY();

At the end I got following message:

ERROR:  Error test
CONTEXT:  Context error
server sent data ("D" message) without prior row description ("T" message)

and also nothing appears in a log file. Similar concept is used in
autovacuum.c.

Any idea what is wrong?
    Thanks for help Zdenek


Re: How to handle error message in PG_CATCH

От
Alvaro Herrera
Дата:
Zdenek Kotala wrote:

> PG_TRY();
> {
>     ...
>     ereport(ERROR, (errmsg("Error test")));
>     ...
> }
> PG_CATCH();
> {
>     errcontext("Context error");
>         EmitErrorReport();
>         FlushErrorState();
> }
> PG_END_TRY();
>
> At the end I got following message:
>
> ERROR:  Error test
> CONTEXT:  Context error
> server sent data ("D" message) without prior row description ("T" message)

I don't see anything wrong with this code.  Perhaps the problem is
somewhere else?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Re: How to handle error message in PG_CATCH

От
Zdenek Kotala
Дата:
Alvaro Herrera napsal(a):
> Zdenek Kotala wrote:
> 
>> PG_TRY();
>> {
>>     ...
>>     ereport(ERROR, (errmsg("Error test")));
>>     ...
>> }
>> PG_CATCH();
>> {
>>     errcontext("Context error");
>>         EmitErrorReport();
>>         FlushErrorState();
>> }
>> PG_END_TRY();
>>
>> At the end I got following message:
>>
>> ERROR:  Error test
>> CONTEXT:  Context error
>> server sent data ("D" message) without prior row description ("T" message)
> 
> I don't see anything wrong with this code.  Perhaps the problem is
> somewhere else?
> 


There is whole test code. It is store procedure and there are nothing 
special.  The difference between this and autovacuum is that autovacuum 
works without client side.

Datum
pg_check(PG_FUNCTION_ARGS)
{PG_TRY();{            ereport(ERROR, (errmsg("Error test")));        }        PG_CATCH();        {
errcontext("Contexterror");            EmitErrorReport();            FlushErrorState();        }
PG_END_TRY();PG_RETURN_DATUM(0);
}

    Zdenek


Re: How to handle error message in PG_CATCH

От
Tom Lane
Дата:
Zdenek Kotala <Zdenek.Kotala@Sun.COM> writes:
> Alvaro Herrera napsal(a):
>> Zdenek Kotala wrote:
>>> At the end I got following message:
>>> 
>>> ERROR:  Error test
>>> CONTEXT:  Context error
>>> server sent data ("D" message) without prior row description ("T" message)
>> 
>> I don't see anything wrong with this code.  Perhaps the problem is
>> somewhere else?

> There is whole test code. It is store procedure and there are nothing 
> special.  The difference between this and autovacuum is that autovacuum 
> works without client side.

The problem with this is it's violating the wire protocol.  Once you've
sent the client an ERROR message, it no longer expects to see any result
from the SELECT that called the function.
        regards, tom lane


Re: How to handle error message in PG_CATCH

От
Zdenek Kotala
Дата:
Tom Lane napsal(a):
> Zdenek Kotala <Zdenek.Kotala@Sun.COM> writes:
>> Alvaro Herrera napsal(a):
>>> Zdenek Kotala wrote:
>>>> At the end I got following message:
>>>>
>>>> ERROR:  Error test
>>>> CONTEXT:  Context error
>>>> server sent data ("D" message) without prior row description ("T" message)
>>> I don't see anything wrong with this code.  Perhaps the problem is
>>> somewhere else?
> 
>> There is whole test code. It is store procedure and there are nothing 
>> special.  The difference between this and autovacuum is that autovacuum 
>> works without client side.
> 
> The problem with this is it's violating the wire protocol.  Once you've
> sent the client an ERROR message, it no longer expects to see any result
> from the SELECT that called the function.
> 

Thanks for explanation. I added extra error message at the end of 
function and it works now.

    Thanks Zdenek