pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feeddblink question about duplicate connection
2+ messages / 2 participants
[nested] [flat]
* dblink question about duplicate connection
@ 2011-08-02 12:36 francescoboccacci@libero.it <francescoboccacci@libero.it>
2011-08-02 20:46 ` Re: dblink question about duplicate connection Joe Conway <mail@joeconway.com>
0 siblings, 1 reply; 2+ messages in thread
From: francescoboccacci@libero.it @ 2011-08-02 12:36 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: dblink question about duplicate connection
2011-08-02 12:36 dblink question about duplicate connection francescoboccacci@libero.it <francescoboccacci@libero.it>
@ 2011-08-02 20:46 ` Joe Conway <mail@joeconway.com>
0 siblings, 0 replies; 2+ messages in thread
From: Joe Conway @ 2011-08-02 20:46 UTC (permalink / raw)
To: francescoboccacci@libero.it <francescoboccacci@libero.it>; +Cc: pgsql-admin
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2011-08-02 20:46 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-08-02 12:36 dblink question about duplicate connection francescoboccacci@libero.it <francescoboccacci@libero.it>
2011-08-02 20:46 ` Joe Conway <mail@joeconway.com>
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