Error handling in C API function calls in a way that doesn't close client connection - Mailing list pgsql-general

From Igor Stassiy
Subject Error handling in C API function calls in a way that doesn't close client connection
Date
Msg-id CAKVOjezz=NEa+U7mH4XYA-n1XNZ3TSinBtP-wbit3oATz+wCDQ@mail.gmail.com
Whole thread Raw
Responses Re: Error handling in C API function calls in a way that doesn't close client connection  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: John McKown
Date:
Subject: Re: The case of PostgreSQL on NFS Server (II)
Next
From: Octavi Fors
Date:
Subject: Re: The case of PostgreSQL on NFS Server (II)