2
我需要从不同查询汇总的联合表,并从存储过程返回整个结果集。这里是我的意思:是否有可能在postgresql中结合结果?
CREATE OR REPLACE FUNCTION invalid_pa() RETURNS TABLE (p_id int) AS $$
DECLARE
pl int[] := ARRAY(SELECT id FROM p.pl);
BEGIN
FOR i IN 1 .. array_upper(platforms, 1)
LOOP
--The query is SELECT id FROM dblink(connection_str(i), 'Some query')
--I need to union all the query above
--and return the unioned table
END LOOP;
END $$
LANGUAGE plpgsql;
我怎样才能以这种方式联合不同的结果集?
connection_str(i)
这里是一个存储过程返回的实际连接字符串
是的,使用动态SQL(执行$ s $ select * from $ s $ || tanlename || $ s $ union ..... $ s $ –