Обсуждение: connecting to a differnt DB in PL/pgSQL
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. ______________________________________________________________________ Yahoo! Cellulari: loghi, suonerie, picture message per il tuo telefonino http://it.yahoo.com/mail_it/foot/?http://it.mobile.yahoo.com/index2002.html
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
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
Avevo gia' risolto il come farlo,
ma grazie lo stesso
Ciao
Danilo
--- Franco Bruno Borghesi
<franco@akyasociados.com.ar> ha scritto: > 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.
>
>
>
>
______________________________________________________________________
Yahoo! Cellulari: loghi, suonerie, picture message per il tuo telefonino
http://it.yahoo.com/mail_it/foot/?http://it.mobile.yahoo.com/index2002.html