Bird
0
0

Consider this PostgreSQL function snippet:

medium📝 query result Q13 of 15
PostgreSQL - PL/pgSQL Fundamentals
Consider this PostgreSQL function snippet:
FOR i IN 1..3 LOOP
  RETURN NEXT i;
END LOOP;
RETURN;

What will be the output when this function is called?
ASyntax error due to RETURN NEXT usage
B[3]
CNo output, function ends without returning
D[1, 2, 3]
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop with RETURN NEXT

    The loop runs from 1 to 3, and each iteration adds the current number to the output using RETURN NEXT.
  2. Step 2: Understand the final RETURN

    The final RETURN ends the function after all rows have been added, so the output is all numbers collected.
  3. Final Answer:

    [1, 2, 3] -> Option D
  4. Quick Check:

    RETURN NEXT adds rows; final RETURN stops function [OK]
Quick Trick: RETURN NEXT inside loop collects rows; final RETURN stops [OK]
Common Mistakes:
  • Thinking only last value is returned
  • Confusing RETURN NEXT with RETURN
  • Expecting syntax error from RETURN NEXT

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes