我想遍历模式并获得如下所示的结果集:
Count
5
834
345
34
984
但是,我无法让它使用动态 sql 返回任何内容……我已经尝试了所有方法,但 8.2 真的很痛苦。无论我输入什么返回类型,我都会收到此错误:
ERROR: ERROR: RETURN cannot have a parameter in function returning
set
这是我的功能:
CREATE OR REPLACE FUNCTION dwh.adam_test4()
RETURNS void
LANGUAGE plpgsql
AS $function$
DECLARE
myschema text;
rec RECORD;
BEGIN
FOR myschema IN select distinct c.table_schema, d.p_id
from information_schema.tables t inner join information_schema.columns c
on (t.table_schema = t.table_schema and t.table_name = c.table_name)
join dwh.sgmt_clients d on c.table_schema = lower(d.userid)
where c.table_name = 'fact_members' and c.column_name = 'debit_card'
and t.table_schema NOT LIKE 'pg_%'
and t.table_schema NOT IN ('information_schema', 'ad_delivery', 'dwh', 'users', 'wand', 'ttd')
order by table_schema
LOOP
EXECUTE 'select count(ucic) from '|| myschema || '.' ||'fact_members where debit_card = ''yes''' into rec;
RETURN rec;
END LOOP;
END
$function$