Bird
0
0

What will be the output of the following PL/pgSQL block?

medium📝 query result Q4 of 15
PostgreSQL - PL/pgSQL Fundamentals

What will be the output of the following PL/pgSQL block?

DO $$
DECLARE
  temperature INT := 15;
BEGIN
  IF temperature >= 30 THEN
    RAISE NOTICE 'Hot';
  ELSIF temperature >= 20 THEN
    RAISE NOTICE 'Warm';
  ELSIF temperature >= 10 THEN
    RAISE NOTICE 'Cool';
  ELSE
    RAISE NOTICE 'Cold';
  END IF;
END $$;
A'Warm'
B'Cool'
C'Hot'
D'Cold'
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate conditions in order

    Check if temperature (15) >= 30? No.
  2. Step 2: Next condition

    Check if temperature >= 20? No.
  3. Step 3: Next condition

    Check if temperature >= 10? Yes, 15 >= 10.
  4. Final Answer:

    'Cool' -> Option B
  5. Quick Check:

    Conditions checked top-down, first true triggers output [OK]
Quick Trick: Conditions checked top to bottom, first true wins [OK]
Common Mistakes:
  • Selecting 'Warm' or 'Hot' without checking order
  • Ignoring ELSE block
  • Misreading comparison operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes