Bird
0
0

Why does this function declaration cause an error?

medium📝 Debug Q6 of 15
PostgreSQL - Advanced PL/pgSQL
Why does this function declaration cause an error?
CREATE FUNCTION test_func(VARIADIC nums int) RETURNS int AS $$
  SELECT sum(nums);
$$ LANGUAGE sql;
AVARIADIC keyword cannot be used in SQL language functions
BFunction body syntax is incorrect
Csum() cannot be used inside functions
DVARIADIC parameter must be declared as an array type
Step-by-Step Solution
Solution:
  1. Step 1: Check VARIADIC parameter type

    VARIADIC parameters must be declared as arrays, but here it is declared as int (scalar).
  2. Step 2: Identify error cause

    This mismatch causes a syntax error when creating the function.
  3. Final Answer:

    VARIADIC parameter must be declared as an array type -> Option D
  4. Quick Check:

    VARIADIC parameter type error = array required [OK]
Quick Trick: VARIADIC must be array type, not scalar [OK]
Common Mistakes:
  • Declaring VARIADIC as scalar type
  • Assuming sum() causes error
  • Thinking VARIADIC disallowed in SQL functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes