我正在创建一个获取两个数组的函数,一个整数和一个字符串然后创建一个物化视图,并用这些参数的串联命名。这样:
CREATE OR REPLACE FUNCTION reports_mt_views(
accounts integer[],
namesa text[])
RETURNS void AS
$BODY$
DECLARE
i integer;
BEGIN
FOREACH i IN ARRAY accounts
LOOP
EXECUTE 'CREATE MATERIALIZED VIEW pps.order_reports_materialized_' || accounts[i] || '_' || namesa[i] || ' AS
...
然而,当我按如下方式启动该功能时:
SELECT reports_mt_views(ARRAY [1,9,504231,505674], '{''a'',''b'',''c'',''d''}');
我收到以下错误:
ERROR: syntax error at or near "'a'"
LINE 1: ...TE MATERIALIZED VIEW pps.order_reports_materialized_1_'a'
这是因为我发送的简单引号。否则我不能发送字符串数组,如果我这样做:
SELECT reports_mt_views(ARRAY [1,9,504231,505674], {'a','b','c','d'}, 3);
ERROR: syntax error at or near "{"
LINE 1: ...T pps.reports_mt_views(ARRAY [1,9,504231,505674], {'a','b','...
^
我无法发送和读取字符串数组以生成实体化视图的名称。