X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 3F472D1CACB for ; Fri, 13 Feb 2004 09:30:00 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 00850-10 for ; Fri, 13 Feb 2004 05:30:00 -0400 (AST) Received: from crommail.cromwell-tools.co.uk (host217-40-164-180.in-addr.btopenworld.com [217.40.164.180]) by svr1.postgresql.org (Postfix) with ESMTP id 2D3ACD1C515 for ; Fri, 13 Feb 2004 05:29:57 -0400 (AST) Message-ID: <402C994F.8030209@cromwell.co.uk> Date: Fri, 13 Feb 2004 09:30:55 +0000 From: Mark Gibson MIME-Version: 1.0 To: =?ISO-8859-1?Q?Gezeala_=27Eyah=27_Bacu=F1o_II?= Cc: pgsql-php@postgresql.org Subject: Re: How To Connect to another Database inside a plpgsql function References: <20040213085655.67695.qmail@web41408.mail.yahoo.com> In-Reply-To: <20040213085655.67695.qmail@web41408.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/30 X-Sequence-Number: 2578 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 Web Developer & Database Admin Cromwell Tools Ltd. Leicester, England.