Bird
0
0

You wrote this function:

medium📝 Debug Q14 of 15
PostgreSQL - PL/pgSQL Fundamentals
You wrote this function:
CREATE FUNCTION test_func() RETURNS SETOF integer AS $$
DECLARE
  i integer := 1;
BEGIN
  RETURN i;
  RETURN NEXT i + 1;
END;
$$ LANGUAGE plpgsql;

What is the problem with this function?
ARETURN NEXT is used after RETURN, so it never executes.
BRETURN cannot be used in functions returning SETOF.
CVariable i is not initialized properly.
DFunction lacks a LOOP to return multiple rows.
Step-by-Step Solution
Solution:
  1. Step 1: Check order of RETURN and RETURN NEXT

    RETURN immediately ends the function, so RETURN NEXT after it never runs.
  2. Step 2: Understand function behavior

    Because RETURN is first, only one row is returned and the rest is ignored.
  3. Final Answer:

    RETURN NEXT is used after RETURN, so it never executes. -> Option A
  4. Quick Check:

    RETURN stops function; code after it is skipped [OK]
Quick Trick: RETURN stops function; code after it won't run [OK]
Common Mistakes:
  • Assuming RETURN NEXT runs after RETURN
  • Thinking RETURN can't be used in SETOF functions
  • Believing variable initialization causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes