Bird
0
0

Identify the error in this function:

medium📝 Debug Q14 of 15
PostgreSQL - Advanced PL/pgSQL
Identify the error in this function:
CREATE FUNCTION get_data() RETURNS TABLE(id INT, val TEXT) AS $$ BEGIN RETURN SELECT 1, 'a'; END; $$ LANGUAGE plpgsql;
AMissing RETURN QUERY before SELECT
BWrong column types in RETURNS TABLE
CFunction must return VOID
DMissing LANGUAGE declaration
Step-by-Step Solution
Solution:
  1. Step 1: Check RETURN statement in RETURNS TABLE function

    In PL/pgSQL, to return rows from a query, use RETURN QUERY, not just RETURN.
  2. Step 2: Identify missing RETURN QUERY

    The function uses RETURN SELECT which is invalid syntax; it should be RETURN QUERY SELECT.
  3. Final Answer:

    Missing RETURN QUERY before SELECT -> Option A
  4. Quick Check:

    Use RETURN QUERY to return rows in RETURNS TABLE [OK]
Quick Trick: Use RETURN QUERY, not RETURN, to return table rows [OK]
Common Mistakes:
  • Using RETURN instead of RETURN QUERY for table results
  • Omitting LANGUAGE plpgsql
  • Incorrect RETURNS TABLE column types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes