0

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.

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

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.
0

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.

1 Comment

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.