From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Frankie Lam <frankie(at)ucr(dot)com(dot)hk> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: dblink question please |
Date: | 2003-02-13 04:19:03 |
Message-ID: | 3E4B1CB7.90309@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Frankie Lam | 2003-02-13 04:32:54 | Re: dblink question please |
Previous Message | Bruno Wolff III | 2003-02-13 02:19:07 | Re: Possible bug in Postgres? Followup to "How do you select from a table until a condition is met?" |