Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
PostgreSQL - PL/pgSQL Fundamentals
What is wrong with this code snippet?
DECLARE
  arr integer[] := ARRAY[1,2,3];
  val integer;
BEGIN
  FOREACH val LOOP
    RAISE NOTICE '%', val;
  END LOOP;
END;
AVariable val should be text, not integer
BFOREACH missing 'IN ARRAY arr' clause
CRAISE NOTICE cannot print integers
DArray declaration syntax is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Review FOREACH syntax

    FOREACH requires specifying the array to iterate over with 'IN ARRAY arr'.
  2. Step 2: Identify missing clause

    The code misses 'IN ARRAY arr' after FOREACH val.
  3. Final Answer:

    FOREACH missing 'IN ARRAY arr' clause -> Option B
  4. Quick Check:

    FOREACH must specify array source [OK]
Quick Trick: FOREACH must include 'IN ARRAY arr' [OK]
Common Mistakes:
  • Leaving out 'IN ARRAY arr'
  • Changing variable type unnecessarily
  • Misunderstanding RAISE NOTICE usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes