Re: Insert into other database

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Rodolfo Campos <camposer(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Insert into other database
Date: 2006-02-08 22:20:57
Message-ID: 20060208222056.GA48038@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message James Harper 2006-02-08 22:26:01 Re: Insert into other database
Previous Message Rodolfo Campos 2006-02-08 21:59:19 Insert into other database