Amazon web services 将存储过程结果集保存到表中

Amazon web services 将存储过程结果集保存到表中,amazon-web-services,stored-procedures,amazon-redshift,Amazon Web Services,Stored Procedures,Amazon Redshift,我创建了一个存储过程,它返回不同的表\u模式名。我的数据库正在使用红移,我正在使用SQL workbench/J创建它 根据AMAZON Redshift的建议,我们可以使用光标返回结果集。下面是我的代码 CREATE OR REPLACE PROCEDURE get_dist_schema(rsout INOUT refcursor) AS $$ BEGIN OPEN rsout FOR SELECT DISTINCT table_schema FROM information_sche

我创建了一个存储过程,它返回不同的表\u模式名。我的数据库正在使用红移,我正在使用SQL workbench/J创建它

根据AMAZON Redshift的建议,我们可以使用光标返回结果集。下面是我的代码

CREATE OR REPLACE PROCEDURE get_dist_schema(rsout INOUT refcursor)
AS $$
BEGIN 
  OPEN rsout FOR SELECT DISTINCT table_schema FROM information_schema.tables;
END;
$$ LANGUAGE plpgsql;

BEGIN;
CALL get_dist_schema('sname');
FETCH ALL FROM sname;

commit;
从sname获取全部数据的结果如下所示:

table_schema
tableA
tableB
tableC
tableD
我想将结果保存在一个表中,这样当我为一个表执行select语句时,同样的结果也会出现

我试过这个:

BEGIN;
CALL get_dist_schema('sname');
FETCH ALL FROM sname INTO public.distTable
错误显示为:

Invalid operation: syntax error at or near "INTO" 
Position: 22;
有什么办法可以把结果保存到表中吗? 将sname中的所有内容提取到public.distTable中

更新: 如果我使用选择进入:

CREATE OR REPLACE PROCEDURE get_dist_schema(rsout INOUT refcursor)
AS $$
BEGIN 
  OPEN rsout FOR SELECT DISTINCT table_schema INTO public.distTable FROM information_schema.tables;
END;
$$ LANGUAGE plpgsql;
错误:

CALL get_dist_schema('sname')

[Amazon](500310) Invalid operation: Column "table_schema" has unsupported type "information_schema.sql_identifier".;

您不能只使用
创建表distTable作为从信息模式选择不同的表模式。表
?我需要使用存储过程,因为我需要从红移动态获取数据。我尝试了您在这里建议的类似方法:但是有问题您要插入的表是否已经存在?您是否尝试使用
选择将存储过程的结果包装到
()中?是的,该表已存在。我已尝试将信息从模式中选择到表中。我在这里提出了一个问题,我用select into编辑了上面的代码