我想在Amazon Redshift上执行存储在字符串字段中的动态@R_502_194@.
我的背景主要是T-sql关系数据库.我曾经动态地构建sql语句,将它们存储到变量中并执行它们.我知道Redshift可以准备和执行语句,但我想知道是否可以执行存储在字符串字段中的查询.
我有一段代码使用pg_ *系统表在几个表上使用stats动态构建下面的代码.每个列/表名都是动态计算的.以下是查询输出的示例:
SELECT h_article_id AS key,'transport_parameters_weight_in_grams' AS col_name,COUNT(DISTINCT transport_parameters_weight_in_grams) AS count_value FROM dv.s_products GROUP BY h_article_id UNION ALL SELECT h_article_id AS key,'transport_parameters_width_in_mm' AS col_name,COUNT(DISTINCT transport_parameters_width_in_mm) AS count_value FROM dv.s_products GROUP BY h_article_id UNION ALL SELECT h_article_id AS key,'label_owner_info_communication_address' AS col_name,COUNT(DISTINCT label_owner_info_communication_address) AS count_value FROM dv.s_products GROUP BY h_article_id
我想在另一个查询中输入这个动态的代码片段,所以我可以做一些统计信息,如下所示:
SELECT col_name,AVG(count_value*1.00) AS avg_count FROM ( 'QUERY ABOVE' ) A GROUP BY col_name;
col_name avg_count transport_parameters_weight_in_grams 1.00 transport_parameters_width_in_mm 1.00 label_owner_info_communication_address 0.60