【发布时间】:2016-10-24 07:59:25
【问题描述】:
在 PostgreSQL 9.1 中,我需要将表名作为参数传递给要在游标中使用的函数 - 然后像这样调用函数:
select myfunction('tableA');
或:
select myfunction('tableB')
我试过这个:
create or replace function myfunction(sid text)
returns integer as $BODY$
declare
bids cursor is select id from sid; --line 4
begin
for bid in bids loop
--some logic
end loop;
return 1;
end;
$BODY$
language plpgsql volatile;
我收到error on line 4。我明白了,不允许将表名作为函数参数传递,允许休息(选择,投影)。
是否有其他方法可以实现这一目标?
【问题讨论】:
标签: postgresql cursor plpgsql postgresql-9.1 dynamic-sql