【发布时间】:2022-11-22 21:29:56
【问题描述】:
我有一个名为list_customers 的函数,将i_entity_id, i_finyear 作为输入参数。模式名称是从i_finyear 构建的,我需要根据给定的模式执行查询。
我尝试了以下代码:
CREATE OR REPLACE FUNCTION list_customers(i_entity_id integer,
i_finyear integer)
RETURNS TABLE(entity_id integer, client_id
integer, financial_yr integer) LANGUAGE 'plpgsql' AS
$BODY$
declare finyear integer := i_finyear;
schema_1 text := 'tds'||''||i_finyear;
begin
set search_path to schema_1;
return query select
d.entity_id, d.client_id, d.financial_yr
from schema_1.deductor d where d.entity_id = 1331;
end;
$BODY$;
然后:
select tds2020.list_customers(1331,2022);
【问题讨论】:
标签: postgresql plpgsql dynamic-sql postgresql-11