Re: connecting to a differnt DB in PL/pgSQL

From: Franco Bruno Borghesi <franco(at)akyasociados(dot)com(dot)ar>
To: Tomasz Myrta <jasiek(at)klaster(dot)net>, friedrich nietzsche <nietzsche_psql(at)yahoo(dot)it>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: connecting to a differnt DB in PL/pgSQL
Date: 2003-04-14 17:16:08
Message-ID: 200304141416.08254.franco@akyasociados.com.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

you should install dblink as Tomasz said. To do that:

cd ...../postgresql-7.3.2/contrib/dblink
gmake
gmake install

then you enter into psql to create the functions:
\i dblink.psql

then you try (change the params):

SELECT
*
FROM
dblink('host=localhost port=5432 dbname=franco user=admin password=1234',
'SELECT id, name FROM people')
AS (id INTEGER, people TEXT);

If you skip the values host, port, ..., the defaults will be used.
If it works in psql, it should work inside a function.

On Monday 14 April 2003 12:45, Tomasz Myrta wrote:
> Uz.ytkownik friedrich nietzsche napisa?:
> > Hi all,
> > Is it possible to connect to another database within a
> > PL/PgSQL function?
> >
> > I'm in a function on the "A" database and I need to
> > retrieve some information from a table in a different
> > Database "B"
> >
> > may someone help me?
> >
> > thanks, Danilo.
> > bye.
>
> You can't access another database even inside 1 server directly.
> Find something about contrib/dblink - maybe it will help you.
>
> Regards,
> Tomasz Myrta
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message mdc@keko.com.ar 2003-04-14 22:07:14 help with query!!!
Previous Message Tomasz Myrta 2003-04-14 15:45:01 Re: connecting to a differnt DB in PL/pgSQL