PG_TRY & PG_CATCH in FDW development

From: Abbas Butt <abbas(dot)butt(at)enterprisedb(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: PG_TRY & PG_CATCH in FDW development
Date: 2017-04-25 14:00:34
Message-ID: CALtH27dXkcWn5i51tKNDBU2jVqPBbQkELzgio8OUxwEgdn20LA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

I want to share a technical problem that I am facing while writing code for
an FDW.
The problem is as follows:
In the FDW call back functions it is recommended to use PG_TRY PG_CATCH
blocks along with PG_RE_THROW to disconnect from the foreign server.
I am using the same technique in IterateForeignScan function, and it is
supposed to work like this:

1 PG_TRY();
2 {
3 ... code that might throw ereport(ERROR) ...
4 }
5 PG_CATCH();
6 {
7 disconnect_from_foreign_server();
8 PG_RE_THROW();
9 }
10 PG_END_TRY();

PG_RE_THROW is supposed to throw the same error again and then take us out
of the function.

What is happening for me is that PG_RE_THROW takes me to PG_TRY in the same
function and then PG_TRY jumps to PG_CATCH where PG_RE_THROW again jumps to
PG_TRY in the same function resulting in an infinite loop. The query
therefore never returns. It is supposed to throw the error and quit.
My question is what could possibly cause this infinite loop?

Thanks in advance.

--
--
*Abbas*
Architect

Ph: 92.334.5100153
Skype ID: gabbasb
www.enterprisedb.co <http://www.enterprisedb.com/>m
<http://www.enterprisedb.com/>

*Follow us on Twitter*
@EnterpriseDB

Visit EnterpriseDB for tutorials, webinars, whitepapers
<http://www.enterprisedb.com/resources-community> and more
<http://www.enterprisedb.com/resources-community>

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-04-25 14:07:13 Re: OK, so culicidae is *still* broken
Previous Message Bruce Momjian 2017-04-25 14:00:04 Re: PG 10 release notes