Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top