【问题标题】:How to run a SQL query stored inside Redshift table如何运行存储在 Redshift 表中的 SQL 查询
【发布时间】:2019-06-11 06:34:11
【问题描述】:

我想运行在 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;|
-------------------------------------------

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

【问题讨论】:

标签: sql amazon-web-services amazon-redshift


【解决方案1】:

您也许可以通过Creating Stored Procedures in Amazon Redshift 实现这一目标。

我注意到Supported PL/pgSQL Statements 包括:

动态 SQL

要在每次从 PL/pgSQL 存储过程运行时生成可能涉及不同表或不同数据类型的动态命令,请使用 EXECUTE 语句。

EXECUTE command-string [ INTO target ];

【讨论】:

  • 同意。但这将如何帮助我将表中已经存在的查询提取为数据?
  • 当你CALL存储过程时,你可以传入包含查询的字符串。然后存储过程应该能够传回查询的结果。
猜你喜欢
  • 1970-01-01
  • 2020-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-23
相关资源
最近更新 更多