PostgreSQL 可以在两个 SQL 服务器存储过程之间执行连接吗?

Can PostgreSQL perform a join between two SQL Server stored procedures?

这个问题与之前的问题有关:

在 SQL 服务器上,您无法执行连接到(或 select 来自)存储过程(请注意:存储过程 显然不同于 function(table-valued function in SQL Server terminology)- 使用函数,您知道在设计时返回的列,但是使用过程,要返回的具体列直到运行时才知道)。

对于 SQL 服务器,确实存在一种 "generally not allowed by DBA's" 方法可以完成这样的连接:OPENROWSET

所以问题是:

  1. PostgreSQL 可以在两个过程之间执行连接,其中列在运行时才知道吗?

  2. 除了使用驻留在外部第 3 方数据库中的存储过程(可能通过外部数据包装器或其他机制)外,它能做同样的事情吗?

  1. Can PostgreSQL perform a join between two ~procedures where the columns are not known until runtime?

基本答案很简单,因为 目前 Postgres 中没有存储过程(直到 Postgres 10),只有功能 -提供几乎但不完全相同的功能,正如您在问题中所列出的那样。

并且任何函数都可以像任何其他 table.

一样在 SELECT 查询的 FROM 子句中使用

更新:
SQL 过程 ("stored procedures") 是在 Postgres 11 中引入的。
CREATE PROCEDURE.

的手册

SQL 本身要求在运行时知道 return 类型。有一个 border-case:您可以使用 polymorphic types 通过函数调用声明 return 类型。详细说明在这里(最后一章与您最相关):

  • Refactor a PL/pgSQL function to return the output of various SELECT queries
  1. Can it do the same, except using stored procedures that reside in an external 3rd party database (perhaps via foreign data wrappers or some other mechanism)?

那也是 NO,基于同样的原则。如果您使用 foreign tables,您必须提供明确定义的 return type one or the other way。

可能能够将SQL-服务器存储过程产生的整行集中到单个制表符分隔的文本表示中,但是随后(除了容易出错和效率低下之外)你只有一个列并且需要元信息定义各个列以一种或另一种方式来提取列 - catch 22.