Bird
0
0

Why must cursors in PostgreSQL be declared inside a transaction block?

hard📝 Conceptual Q10 of 15
PostgreSQL - Advanced PL/pgSQL
Why must cursors in PostgreSQL be declared inside a transaction block?
ABecause cursors require exclusive locks on tables
BBecause cursors automatically commit changes after each fetch
CBecause cursors cannot be used with SELECT statements outside transactions
DBecause cursors rely on a stable snapshot of data during the transaction
Step-by-Step Solution
Solution:
  1. Step 1: Understand cursor data consistency

    Cursors provide a stable view of data, which requires a transaction snapshot.
  2. Step 2: Analyze options

    Only Because cursors rely on a stable snapshot of data during the transaction correctly explains the need for transaction block.
  3. Final Answer:

    Because cursors rely on a stable snapshot of data during the transaction -> Option D
  4. Quick Check:

    Transaction needed for stable cursor snapshot [OK]
Quick Trick: Transaction ensures cursor sees consistent data [OK]
Common Mistakes:
  • Thinking cursors auto-commit
  • Believing cursors need exclusive locks
  • Assuming cursors can't use SELECT outside transactions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes