简体   繁体   English

如何从PostgreSQL数据库2中的函数更新数据库1中的表?

[英]How to update table in database1 from function in database2 in PostgreSQL?

Is there a way to update a table in database1 from a function in database2 (both databases are on the same server)? 有没有一种方法可以从database2中的函数更新database1中的表(两个数据库都在同一服务器上)? Basically cross database update in PostgreSQL. 基本上是在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. -=编辑=-我知道我可以使用DBLink做到这一点,但我想尽可能少地修改源数据库。 I'm looking for some other options. 我正在寻找其他选择。

You could put both databases in the same Postgresql database, but in different schemas. 您可以将两个数据库放在同一个Postgresql数据库中,但是放在不同的模式中。

This way, they are still logically separated, and there is no name clash, but you can access objects in between the schemas. 这样,它们在逻辑上仍然是分开的,并且没有名称冲突,但是您可以访问架构之间的对象。

DBLink would be the standard way to do this if it was available. 如果可用,DBLink将是执行此操作的标准方法。 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. 如果没有安装像PL / pgperl这样的过程语言(不是PL / pgsql),则可以使用该语言连接到数据库2并调用更新语句。 Or you could use the procedural language to call a shell script that calls psql to do your update. 或者,您可以使用过程语言来调用Shell脚本,该脚本调用psql进行更新。

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). 您知道PostgreSQL中的数据库是分开的,并且不能(通过设计)直接访问另一个数据库。

You know that the dblink extension lets you connect two databases (same or different server). 您知道dblink扩展使您可以连接两个数据库(相同或不同的服务器)。

You find the dblink extension too invasive (ruling out small_duck's idea of merging the two databases, I suspect). 您会发现dblink扩展太具有侵入性(我怀疑排除了small_duck合并两个数据库的想法)。

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. 考虑到dblink是该区域的默认选择,我不确定您认为会比dblink更简单的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Postgresql中的同一表(Database2)更新表(Database1) - Update a table (Database1) from the same table (Database2) in Postgresql 将数据从数据库1复制到数据库2 - Copy data from database1 to database2 如何使用sql将一个表从database1复制到database2?我的代码结果最终丢失了主键 - How to copy one table from database1 to database2 using sql?My codes result finally lost primary key SQLite:将值从数据库1中的表插入数据库2中的表,而不会覆盖 - SQLite: Inserting values from table in database1 to table in database2 without overwriting 从数据库2获取行的值以加入数据库1 - get the value of rows from database2 to join in database1 如何在SQL Server中将表的数据从database1复制和覆盖到database2 - How can I copy and overwrite data of tables from database1 to database2 in SQL Server 有一个存储在 database1 中的触发器,当 database2 中的表被更新时触发,两个数据库都在链接服务器中? - Have a trigger stored in database1 that triggers when a table in database2 is updated, both databases in a linked server? 将来自database2的值放到我当前的数据库中 - put values from database2 to my current database 如何从Access查询PostgreSQL数据库表? - How to query PostgreSQL database table from Access? 有效地更新非常大的PostgreSQL数据库表 - Update VERY LARGE PostgreSQL database table efficiently
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM