pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: francescoboccacci@libero.it <francescoboccacci@libero.it>
To: pgsql-admin@postgresql.org
Subject: dblink question about duplicate connection
Date: Tue, 2 Aug 2011 14:36:08 +0200 (CEST)
Message-ID: <13669451.4531041312288568915.JavaMail.defaultUser@defaultHost> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <13669451.4531041312288568915.JavaMail.defaultUser@defaultHost>
Permalink:  ../13669451.4531041312288568915.JavaMail.defaultUser@defaultHost/
Also on:    postgresql.org/message-id/13669451.4531041312288568915.JavaMail.defaultUser@defaultHost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: francescoboccacci@libero.it
  Subject: Re: dblink question about duplicate connection
  In-Reply-To: <13669451.4531041312288568915.JavaMail.defaultUser@defaultHost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox