作为调用函数的结果,是否可以简单地传递由dblink()
up 生成的结果记录,例如:
create function execute_generic_sql_on_remote_databases(_sql text)
return set of record
language plpgsql
as $$
declare
r record; -- this is already not a real record
begin
-- get connections to several DBs
...
-- send _sql queries to the DBs
...
-- get results of query execution
loop through connections
for r in select MAGIC from dblink_get_results(conn, _sql) loop
return next r;
end loop;
end loop;
-- close connections
...
end;
$$;
dblink
可以像实际上一样调用此函数:
select * from execute_generic_sql_on_remote_databases('SELECT 1') as r(i int);
但它需要一些MAGIC
. :(
可以plProxy
很容易地做到这一点,但问题是如何用 来做到这一点dblink
,如果有可能的话plpgsql
。