Skip to content

VARIADIC

CREATE OR REPLACE FUNCTION total_sum(VARIADIC arr integer[]) RETURNS integer AS $$
BEGIN
RETURN array_sum(arr);
END; $$ LANGUAGE plpgsql;
SELECT total_sum(10, 20, 30, 40);
100

The function total_sum is declared with the VARIADIC keyword, which allows it to take an unspecified number of arguments. In the SELECT statement, four integers are provided as arguments. The result is the sum of these four integers, which is ‘100’.