Re: dblink question please - Mailing list pgsql-sql

From Joe Conway
Subject Re: dblink question please
Date
Msg-id 3E4B1CB7.90309@joeconway.com
Whole thread Raw
In response to dblink question please  ("Frankie Lam" <frankie@ucr.com.hk>)
List pgsql-sql
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




pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Possible bug in Postgres? Followup to "How do you select from a table until a condition is met?"
Next
From: "Frankie Lam"
Date:
Subject: Re: dblink question please