pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Gibson <gibsonm@cromwell.co.uk>
To: Gezeala 'Eyah' Bacuño II <gezeala25@yahoo.com>
Cc: pgsql-php@postgresql.org
Subject: Re: How To Connect to another Database inside a plpgsql function
Date: Fri, 13 Feb 2004 09:30:55 +0000
Message-ID: <402C994F.8030209@cromwell.co.uk> (raw)
In-Reply-To: <20040213085655.67695.qmail@web41408.mail.yahoo.com>
References: <20040213085655.67695.qmail@web41408.mail.yahoo.com>

Gezeala 'Eyah' Bacuño II wrote:

> Hi Guys!
>  
> I have 2 database namely "DB1" and "DB2".
>  
> In DB1 I created a plgpsql function fnTest().
>  
> My problem is inside fnTest() I need to check some tables in DB2! I've 
> no idea how to do this. Usually when I make a function I only access 
> tables/views/functions in the same database. I really don't know if 
> this is possible.
>  

Take a look at contrib/dblink, it allows cross database queries like this:

SELECT *
FROM
    dblink('host=myhost dbname=DB1 user=me',
        'SELECT col1, col2, col3
         FROM mytable')
         AS t (col1 integer, col2 text, col3 real);

-- 
Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk>
Web Developer & Database Admin
Cromwell Tools Ltd.
Leicester, England.




view thread (3+ messages)  latest in thread

Message-ID: <402C994F.8030209@cromwell.co.uk>
Permalink:  ../402C994F.8030209@cromwell.co.uk/
Also on:    postgresql.org/message-id/402C994F.8030209@cromwell.co.uk

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: gibsonm@cromwell.co.uk, gezeala25@yahoo.com
  Subject: Re: How To Connect to another Database inside a plpgsql function
  In-Reply-To: <402C994F.8030209@cromwell.co.uk>
  References: <20040213085655.67695.qmail@web41408.mail.yahoo.com> <402C994F.8030209@cromwell.co.uk>

* 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