Error handling in C API function calls in a way that doesn't close client connection

Поиск
Список
Период
Сортировка
От Igor Stassiy
Тема Error handling in C API function calls in a way that doesn't close client connection
Дата
Msg-id CAKVOjezz=NEa+U7mH4XYA-n1XNZ3TSinBtP-wbit3oATz+wCDQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Error handling in C API function calls in a way that doesn't close client connection  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hello all,

This question refers to version 9.4 of Postgres. I have have a function

Datum do_something(PG_FUNCTION_ARGS)
{
    ...
    if(error_occured) {
        ereport(ERROR, (errmsg("some error occured")));
    }
    ...
}

When I call do_something in a way to deliberately cause the error condition, the client connection (psql) is terminated, however for example when you say (or many other function calls that cause ereport to be called):

psql > SELECT ST_IsSimple('POINT(1, 1)');

I simply get the message "ERROR:  parse error - invalid geometry" but the connection is not closed. 

The subqueries also know that the inner query had terminated with an error somehow, without terminating the connection:

psql> select * from (select st_issimple('point(0, 0)')) as a;

ERROR:  parse error - invalid geometry

I guess this could be done with surrounding the function call with PG_TRY/CATCH however these macros are not present in Postgis code. 

Can you please suggest how to implement this functionality in my code?

Thanks,
Igor

В списке pgsql-general по дате отправления:

Предыдущее
От: John McKown
Дата:
Сообщение: Re: The case of PostgreSQL on NFS Server (II)
Следующее
От: Octavi Fors
Дата:
Сообщение: Re: The case of PostgreSQL on NFS Server (II)