Bird
0
0

Which of the following is the correct syntax to iterate over an integer array arr using FOREACH in PL/pgSQL?

easy📝 Syntax Q12 of 15
PostgreSQL - PL/pgSQL Fundamentals
Which of the following is the correct syntax to iterate over an integer array arr using FOREACH in PL/pgSQL?
AFOREACH element IN ARRAY arr LOOP ... END LOOP;
BFOREACH element FROM arr LOOP ... END LOOP;
CFOREACH element ON arr LOOP ... END LOOP;
DFOREACH element OVER arr LOOP ... END LOOP;
Step-by-Step Solution
Solution:
  1. Step 1: Recall FOREACH syntax

    The correct syntax uses 'IN ARRAY' to specify the array to loop over.
  2. Step 2: Match syntax options

    Only FOREACH element IN ARRAY arr LOOP ... END LOOP; uses 'IN ARRAY' correctly; others use invalid keywords.
  3. Final Answer:

    FOREACH element IN ARRAY arr LOOP ... END LOOP; -> Option A
  4. Quick Check:

    FOREACH ... IN ARRAY ... is correct syntax [OK]
Quick Trick: Use 'IN ARRAY' to loop over arrays with FOREACH [OK]
Common Mistakes:
  • Using FROM, ON, or OVER instead of IN ARRAY
  • Omitting LOOP or END LOOP keywords
  • Trying to use FOREACH outside PL/pgSQL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes