Skip site navigation (1) Skip section navigation (2)

Re: How To Connect to another Database inside a plpgsql function

From: Mark Gibson <gibsonm(at)cromwell(dot)co(dot)uk>
To: Gezeala 'Eyah' Bacuño II <gezeala25(at)yahoo(dot)com>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: How To Connect to another Database inside a plpgsql function
Date: 2004-02-13 09:30:55
Message-ID: 402C994F.8030209@cromwell.co.uk (view raw or flat)
Thread:
Lists: pgsql-php
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.


In response to

pgsql-php by date

Next:From: Thom DysonDate: 2004-02-13 17:51:36
Subject: Queries that return permissions
Previous:From: Gezeala 'Eyah' Bacuño IIDate: 2004-02-13 08:56:55
Subject: How To Connect to another Database inside a plpgsql function

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group