X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D23E0475458 for ; Wed, 12 Feb 2003 23:20:50 -0500 (EST) Received: from joeconway.com (unknown [63.210.180.150]) by postgresql.org (Postfix) with ESMTP id 197CB474E5C for ; Wed, 12 Feb 2003 23:20:50 -0500 (EST) Received: from [192.168.5.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.4) with ESMTP-TLS id 1610182; Wed, 12 Feb 2003 20:55:55 -0800 Message-ID: <3E4B1CB7.90309@joeconway.com> Date: Wed, 12 Feb 2003 20:19:03 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Frankie Lam Cc: pgsql-sql@postgresql.org Subject: Re: dblink question please References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/273 X-Sequence-Number: 11671 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