Bird
0
0

Given the function:

medium📝 query result Q4 of 15
PostgreSQL - Advanced PL/pgSQL
Given the function:
CREATE FUNCTION join_words(VARIADIC words text[]) RETURNS text AS $$
  SELECT array_to_string(words, '-');
$$ LANGUAGE sql;

What is the result of SELECT join_words('red', 'green', 'blue');?
A'red-green-blue'
B'{red,green,blue}'
C'red,green,blue'
DError: wrong input type
Step-by-Step Solution
Solution:
  1. Step 1: Understand function behavior

    The function takes a VARIADIC text array and concatenates elements with '-' using array_to_string.
  2. Step 2: Analyze the call

    Calling join_words('red', 'green', 'blue') passes three text arguments as an array {'red','green','blue'}.
  3. Step 3: Result

    The function returns the string 'red-green-blue'.
  4. Final Answer:

    'red-green-blue' -> Option A
  5. Quick Check:

    VARIADIC packs arguments into array, then joined with '-' [OK]
Quick Trick: VARIADIC packs args into array [OK]
Common Mistakes:
  • Expecting array literal output
  • Confusing array_to_string with string_agg
  • Assuming error due to multiple arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes