Bird
0
0

Given this code snippet:

medium📝 query result Q5 of 15
PostgreSQL - PL/pgSQL Fundamentals
Given this code snippet:
DECLARE
  arr text[] := ARRAY['a', 'b', 'c'];
  output text := '';
BEGIN
  FOREACH ch IN ARRAY arr LOOP
    output := output || ch;
  END LOOP;
  RAISE NOTICE '%', output;
END;

What will be printed?
Aa b c
Ba,b,c
Cabc
DError: invalid concatenation
Step-by-Step Solution
Solution:
  1. Step 1: Analyze FOREACH loop

    Each element 'a', 'b', 'c' is concatenated without separator.
  2. Step 2: Result string formation

    Output becomes 'abc' as all letters join directly.
  3. Final Answer:

    abc -> Option C
  4. Quick Check:

    Concatenation without separator = 'abc' [OK]
Quick Trick: Concatenate inside FOREACH for joined string [OK]
Common Mistakes:
  • Expecting commas or spaces automatically
  • Thinking concatenation causes error
  • Assuming FOREACH adds separators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes