views:

112

answers:

3

Hi,

Is there a way to update a table in database1 from a function in database2 (both databases are on the same server)? Basically cross database update in PostgreSQL.

Function is executed by a trigger but it shouldn't matter.

-= edit =- I know I can make it using DBLink but I would like to modify the source database as little as possible. I'm looking for some other options.

A: 

DBLink would be the standard way to do this if it was available. Absent that, if you have a procedural language installed (other than PL/pgsql) like PL/pgperl, you can use that language to connect to database 2 and call your update statement. Or you could use the procedural language to call a shell script that calls psql to do your update.

Mark
Well it seems that there's no other choice. I came to the conclusion that deploying dblink.dll with my app won't be so bad idea after all.Thanks for the answer.
kyrisu
+1  A: 

You could put both databases in the same Postgresql database, but in different schemas.

This way, they are still logically separated, and there is no name clash, but you can access objects in between the schemas.

small_duck
A: 

It's not clear what you're looking for.

You know that databases in PostgreSQL are separate and you can't access one from another directly (by design).

You know that the dblink extension lets you connect two databases (same or different server).

You find the dblink extension too invasive (ruling out small_duck's idea of merging the two databases, I suspect).

I'm not sure what you think would exist that would be simpler than dblink, given that dblink is the default choice in this area.

Richard Huxton
What I'm doing is writing an extension for an app that is using postgresql. I wanted to avoid deploying dblink to mess with the application db as little as possible. Based on the answeres it seems to be only way (having in mind the amount of work and performance of the extension).
kyrisu