Re: Insert into other database - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Insert into other database
Date
Msg-id 20060208222056.GA48038@winnie.fuhr.org
Whole thread Raw
In response to Insert into other database  (Rodolfo Campos <camposer@gmail.com>)
List pgsql-general
On Wed, Feb 08, 2006 at 05:59:19PM -0400, Rodolfo Campos wrote:
> I'm wondering if in postgres we can insert a tuple into a table that is
> outside of a database (I'm supossed to be connected to database1 and want to
> insert a register into a table in database2).

You can do this with contrib/dblink; search the list archives for
other possibilities (PL/Perl + DBI + DBD::Pg, dbi-link, etc.).

> This question is because I want to update a tables into one database from a
> trigger (written in C), and the table who fires the trigger is in another
> database.

A C function can use libpq to connect to another database; that's
how dblink works.  But such a design is often a hint to consider
using separate schemas in the same database rather than separate
databases.  A problem with actions that take place outside the
current database is that you lose transactional control: if the
triggering transaction rolls back then you have no way to roll back
the outside changes.

--
Michael Fuhr

pgsql-general by date:

Previous
From: Rodolfo Campos
Date:
Subject: Insert into other database
Next
From: "James Harper"
Date:
Subject: Re: Insert into other database