VARIADIC parameter must be the last input parameter

我是研究僧i 提交于 2019-12-10 21:02:01

问题


How to create two VARIADIC parameters. Look at my code and correct me.

CREATE OR REPLACE FUNCTION ip_source_test(text,text,date,date,VARIADIC int[],VARIADIC text[])
RETURNS TABLE (no_documents int, "Report By" text, "Report_By" text) AS 
$$
BEGIN
IF 'Source Member' = $1 THEN
RETURN QUERY SELECT.....
ELSEIF 'company' = $1 THEN
RETURN QUERY SELECT.....
ELSE
RAISE NOTICE 'Not Worked';
END IF;
RETURN;
END;
$$ LANGUAGE plpgsql;

Error: VARIADIC parameter must be the last input parameter.

In SQL code im supposed to use 6 parameters. Please update me with sample code.


回答1:


There can be only one VARIADIC per function, since variadic encompasses all the other arguments passed by the caller.

If you mean for the caller to use arrays, there's no point in using variadic anyway, the function signature could look like:

CREATE FUNCTION ip_source_test(text,text,date,date,int[], text[])



回答2:


Just as the error message tells you:

VARIADIC parameter must be the last input parameter.

It follows logically that a function can only take a single VARIADIC parameter as last parameter. There can be other (non-VARIADIC) parameters before that one. Quoting the manual here:

Effectively, all the actual arguments at or beyond the VARIADIC position are gathered up into a one-dimensional array



来源:https://stackoverflow.com/questions/19275206/variadic-parameter-must-be-the-last-input-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!