Re: dblink inside plpgsql function

From: Richard Huxton <dev(at)archonet(dot)com>
To: Loredana Curugiu <loredana(dot)curugiu(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: dblink inside plpgsql function
Date: 2007-07-03 12:58:26
Message-ID: 468A47F2.2030000@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql

Loredana Curugiu wrote:
> CREATE OR REPLACE FUNCTION getReminderServices( varchar ) RETURNS SETOF
> reminder_services AS'
>
> DECLARE r reminder_services%ROWTYPE;
>
> BEGIN
> PERFORM dblink_connect(''dbname=''||$1);

> PERFORM dblink_disconnect($1);
> RETURN;
> END;
> ' LANGUAGE plpgsql;
>
> Now I get the errors:
>
> connection "eu" not available
> CONTEXT: SQL statement "SELECT dblink_disconnect( $1 )"
> PL/pgSQL function "getreminderservices" line 21 at perform

Well, it's complaining that a connection called "eu" isn't available in
the dblink_disconnect() call. I don't use dblink much myself, so I
approached this problem by looking in the documentation.

According to the docs, there are two ways to call dblink_disconnect()
"
Synopsis

dblink_disconnect()
dblink_disconnect(text connname)

Inputs

connname
if an argument is given, it is used as a name for a persistent
connection to close; otherwiase the unnamed connection is closed
"

So - did we open a connection called "eu"? Looking at the docs again, it
appears no! If we use the one-argument version of dblink_connect() we
get an unnamed connection.

So - either change the dblink_disconnect so there is no argument:
dblink_disconnect()

Or change the connection
dblink_connect($1, ''dbname='' || $1)

I'd do the first one, since you don't care what the connection is called
and are closing it at the end of the function.

HTH

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Loredana Curugiu 2007-07-03 13:08:38 Re: [SQL] dblink inside plpgsql function
Previous Message Loredana Curugiu 2007-07-03 12:50:18 Re: [SQL] dblink inside plpgsql function

Browse pgsql-sql by date

  From Date Subject
Next Message Loredana Curugiu 2007-07-03 13:08:38 Re: [SQL] dblink inside plpgsql function
Previous Message Loredana Curugiu 2007-07-03 12:50:18 Re: [SQL] dblink inside plpgsql function