From: Joe Conway <mail@joeconway.com>
To: Frankie Lam <frankie@ucr.com.hk>
Cc: pgsql-sql@postgresql.org
Subject: Re: dblink question please
Date: Wed, 12 Feb 2003 20:19:03 -0800
Message-ID: <3E4B1CB7.90309@joeconway.com> (raw)
In-Reply-To: <b2etmt$26en$1@news.hub.org>
References: <b2etmt$26en$1@news.hub.org>
Frankie Lam wrote:
> Does anyone know if there's a simple way that let dblink function calls in a
> plpgsql function wouldn't raise exception, in case there's sth wrong.
> (e.g. cannot connect to the remote host ......)
Not without hacking dblink.c.
At quick glance it looks like it might be reasonably safe to use
dblink_connect with the lines:
8<---------------------------------
if (PQstatus(persistent_conn) == CONNECTION_BAD)
{
msg = pstrdup(PQerrorMessage(persistent_conn));
PQfinish(persistent_conn);
persistent_conn = NULL;
elog(ERROR, "dblink_connect: connection error: %s", msg);
}
8<---------------------------------
changed to something like (untested)
8<---------------------------------
if (PQstatus(persistent_conn) == CONNECTION_BAD)
{
msg = pstrdup(PQerrorMessage(persistent_conn));
PQfinish(persistent_conn);
persistent_conn = NULL;
elog(NOTICE, "dblink_connect: connection error: %s", msg);
result_text = DatumGetTextP(DirectFunctionCall1(textin,
CStringGetDatum("ERROR")));
PG_RETURN_TEXT_P(result_text);
}
8<---------------------------------
It would be more complex if you want to not use the persistent connection.
HTH,
Joe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mail@joeconway.com, frankie@ucr.com.hk
Subject: Re: dblink question please
In-Reply-To: <3E4B1CB7.90309@joeconway.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox