首页 > 解决方案 > 如何运行存储在 Redshift 表中的 SQL 查询

问题描述

我想运行一个在 Redshift 表中存储为 varchar 的 SQL 查询。有没有办法达到同样的效果?这就是我想要的:

--if we have a text script like this
insert into schema_1.table_1 (id, script) values (1, 'select count(*) from 
schema_2.table_2;');
--is there any way to run this script in SQL?
RunString(select script from schema_1.table_1 where id = 1);

该表如下所示:

___________________________________________
|Id|Query                                 |
|--|--------------------------------------|
|1 |select count(*) from schema_2.table_2;|
-------------------------------------------

简而言之,我想运行上表中的查询。

标签: sqlamazon-web-servicesamazon-redshift

解决方案


You might be able to achieve this by Creating Stored Procedures in Amazon Redshift.

I notice that that Supported PL/pgSQL Statements include:

Dynamic SQL

To generate dynamic commands that can involve different tables or different data types each time they are run from a PL/pgSQL stored procedure, use the EXECUTE statement.

EXECUTE command-string [ INTO target ];

推荐阅读