dblink question about duplicate connection

From: "francescoboccacci(at)libero(dot)it" <francescoboccacci(at)libero(dot)it>
To: pgsql-admin(at)postgresql(dot)org
Subject: dblink question about duplicate connection
Date: 2011-08-02 12:36:08
Message-ID: 13669451.4531041312288568915.JavaMail.defaultUser@defaultHost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Dear all,
i have a question about dblink connection.I use it in a trigger function :

CREATE OR REPLACE FUNCTION setuser()
RETURNS trigger AS
$BODY$

DECLARE

BEGIN
IF (TG_OP = 'INSERT') THEN

PERFORM dblink_connect('conn_test', 'dbname=database_test');

PERFORM dblink_exec('conn_test','insert into users
......

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:

CREATE OR REPLACE FUNCTION setuser()
RETURNS trigger AS
$BODY$

DECLARE

BEGIN
IF (TG_OP = 'INSERT') THEN

If 'conn_test' exist PERFORM dblink_disconnect('conn_test');
else

PERFORM dblink_connect('conn_test', 'dbname=database_test');

PERFORM dblink_exec('conn_test','insert into users

How can write my new function?

Thanks

Francesco Boccacci

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message RBharathi 2011-08-02 12:46:46 Characterset Equivalent for AL32UTF8 in Postgres
Previous Message Lukasz Brodziak 2011-08-02 12:32:07 Re: Gbtreekey16 type