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

From: Igor Stassiy <istassiy(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Error handling in C API function calls in a way that doesn't close client connection
Date: 2015-04-02 23:27:54
Message-ID: CAKVOjezz=NEa+U7mH4XYA-n1XNZ3TSinBtP-wbit3oATz+wCDQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Octavi Fors 2015-04-03 00:09:38 Re: The case of PostgreSQL on NFS Server (II)
Previous Message John McKown 2015-04-02 20:54:27 Re: The case of PostgreSQL on NFS Server (II)