Which of the following is the correct syntax to declare a VARIADIC parameter in a PostgreSQL function?
easy📝 Syntax Q12 of 15
PostgreSQL - Advanced PL/pgSQL
Which of the following is the correct syntax to declare a VARIADIC parameter in a PostgreSQL function?
ACREATE FUNCTION example(VARIADIC nums int[]) RETURNS int AS $$ ... $$ LANGUAGE sql;
BCREATE FUNCTION example(nums VARIADIC int) RETURNS int AS $$ ... $$ LANGUAGE sql;
CCREATE FUNCTION example(nums int VARIADIC) RETURNS int AS $$ ... $$ LANGUAGE sql;
DCREATE FUNCTION example(nums int[]) VARIADIC RETURNS int AS $$ ... $$ LANGUAGE sql;
Step-by-Step Solution
Solution:
Step 1: Identify correct VARIADIC syntax
VARIADIC must precede the parameter name and the parameter type must be an array type, e.g., VARIADIC nums int[].
Step 2: Check each option
CREATE FUNCTION example(VARIADIC nums int[]) RETURNS int AS $$ ... $$ LANGUAGE sql; correctly places VARIADIC before the parameter name and uses an array type. Options A, B, and C misuse the position or syntax of VARIADIC.
Final Answer:
CREATE FUNCTION example(VARIADIC nums int[]) RETURNS int AS $$ ... $$ LANGUAGE sql; -> Option A
Quick Check:
VARIADIC before param name + array type = correct syntax [OK]
Quick Trick:VARIADIC goes before param name and uses array type [OK]
Common Mistakes:
Placing VARIADIC after parameter name
Using non-array type with VARIADIC
Putting VARIADIC after RETURNS keyword
Master "Advanced PL/pgSQL" in PostgreSQL
9 interactive learning modes - each teaches the same concept differently