Bird
0
0

Identify the error in this function:

medium📝 Debug Q6 of 15
PostgreSQL - Advanced PL/pgSQL

Identify the error in this function:

CREATE FUNCTION get_values() RETURNS SETOF integer AS $$ BEGIN RETURN 1; RETURN 2; END; $$ LANGUAGE plpgsql;

AFunction missing LANGUAGE declaration
BUsing RETURN instead of RETURN NEXT for SETOF
CMissing RETURN QUERY statement
DIncorrect RETURNS type
Step-by-Step Solution
Solution:
  1. Step 1: Check RETURN usage for SETOF

    RETURN returns a single value and ends function. For SETOF, RETURN NEXT must be used to add rows.
  2. Step 2: Verify other parts

    LANGUAGE plpgsql is present, RETURNS type is correct, RETURN QUERY is optional alternative.
  3. Final Answer:

    Using RETURN instead of RETURN NEXT for SETOF -> Option B
  4. Quick Check:

    Use RETURN NEXT to add rows in SETOF functions [OK]
Quick Trick: Use RETURN NEXT, not RETURN, in SETOF functions [OK]
Common Mistakes:
  • Using RETURN which ends function early
  • Forgetting to add LANGUAGE plpgsql
  • Confusing RETURN QUERY with RETURN

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes