Bird
0
0

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:
  1. 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[].
  2. 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.
  3. Final Answer:

    CREATE FUNCTION example(VARIADIC nums int[]) RETURNS int AS $$ ... $$ LANGUAGE sql; -> Option A
  4. 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes