将三个多值参数传递给postgresql中的存储过程

时间:2017-07-06 18:18:17

标签: postgresql stored-procedures

我想编写一个存储过程,在postgresql中接受3个多值参数和2个单值参数。

以前,对于1个多值参数,我在postgresql中使用了VARIADIC函数。

1个多值参数的程序 -

CREATE OR REPLACE FUNCTION public.test(
    IN p_fiscal_year integer,
    IN p_program integer,
    VARIADIC text[])
  RETURNS TABLE(period character varying, year integer, amt numeric) AS
$BODY$

BEGIN
    RETURN QUERY
select fiscalperiod.period, fiscalyear.year, SUM(resourcemgmt.estimated_amt) as amt
FROM api_resourcemgmt as resourcemgmt
       INNER JOIN api_fiscalperiod as fiscalperiod ON fiscalperiod.id=resourcemgmt.fiscal_period_id
       INNER JOIN api_fiscalyear as fiscalyear ON fiscalyear.year = fiscalperiod.fiscal_year
       INNER JOIN api_activity as activity ON activity.id = resourcemgmt.activity_id
WHERE fiscalyear.year = p_fiscal_year
AND fiscalperiod.period = ANY($3) --p_month    
AND activity.program_id = p_program 
group by fiscalperiod.period, fiscalyear.year;

END; 
  $BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100

但是如何将3个多值参数传递给postgresql中的存储过程?

例如,我希望存储过程接受输入并在where子句中使用它们。输入将如下 -

select * from stored_procedure(singlevalue1,singlevalue2,multiplevaluefor programs,multiplevaluesforstudents,multiplevalueforgrades);

0 个答案:

没有答案