Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 920D1B5DBD1 for ; Tue, 2 Aug 2011 17:46:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 08993-10 for ; Tue, 2 Aug 2011 20:46:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from joeconway.com (wsip-72-214-29-243.sd.sd.cox.net [72.214.29.243]) by mail.postgresql.org (Postfix) with ESMTP id E1400B5DBC5 for ; Tue, 2 Aug 2011 17:46:21 -0300 (ADT) Received: from www.joeconway.com (account jconway [192.168.4.40] verified) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 11234009; Tue, 02 Aug 2011 13:46:20 -0700 Message-ID: <4E38621C.1040206@joeconway.com> Date: Tue, 02 Aug 2011 13:46:20 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.0.12) Gecko/20071019 Fedora/1.5.0.12-3.fc6 pango-text Thunderbird/1.5.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: "francescoboccacci@libero.it" CC: pgsql-admin@postgresql.org Subject: Re: dblink question about duplicate connection References: <13669451.4531041312288568915.JavaMail.defaultUser@defaultHost> In-Reply-To: <13669451.4531041312288568915.JavaMail.defaultUser@defaultHost> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.918 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RDNS_DYNAMIC=0.982 X-Spam-Level: X-Archive-Number: 201108/13 X-Sequence-Number: 38000 On 08/02/2011 05:36 AM, francescoboccacci@libero.it wrote: > Somentimes happend that an error accours in insert data and when i try to run > new insert posgresql return and error like duplicate connection. > I would like to change my functions in this way: > If 'conn_test' exist PERFORM dblink_disconnect('conn_test'); > else > > PERFORM dblink_connect('conn_test', 'dbname=database_test'); > How can write my new function? See dblink_get_connections(): http://www.postgresql.org/docs/9.0/interactive/contrib-dblink-get-connections.html HTH, Joe -- Joe Conway credativ LLC: http://www.credativ.us Linux, PostgreSQL, and general Open Source Training, Service, Consulting, & 24x7 Support