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