Bird
0
0

What will be the output of this PL/pgSQL function?

medium📝 query result Q13 of 15
PostgreSQL - Advanced PL/pgSQL
What will be the output of this PL/pgSQL function?
CREATE OR REPLACE FUNCTION add_numbers(a INTEGER, b INTEGER) RETURNS INTEGER AS $$
BEGIN
  RETURN a + b;
END;
$$ LANGUAGE plpgsql;

SELECT add_numbers(3, 5);
A8
B35
CSyntax error
DNULL
Step-by-Step Solution
Solution:
  1. Step 1: Understand function logic

    The function takes two integers and returns their sum using RETURN a + b.
  2. Step 2: Evaluate the SELECT call

    Calling add_numbers(3, 5) returns 3 + 5 = 8.
  3. Final Answer:

    8 -> Option A
  4. Quick Check:

    3 + 5 = 8 [OK]
Quick Trick: Add the two input numbers as the function returns sum [OK]
Common Mistakes:
  • Concatenating numbers as strings
  • Expecting syntax error due to missing semicolon
  • Assuming NULL return without explicit return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes