PostgreSQL - Advanced PL/pgSQLWhy must cursors in PostgreSQL be declared inside a transaction block?ABecause cursors require exclusive locks on tablesBBecause cursors automatically commit changes after each fetchCBecause cursors cannot be used with SELECT statements outside transactionsDBecause cursors rely on a stable snapshot of data during the transactionCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand cursor data consistencyCursors provide a stable view of data, which requires a transaction snapshot.Step 2: Analyze optionsOnly Because cursors rely on a stable snapshot of data during the transaction correctly explains the need for transaction block.Final Answer:Because cursors rely on a stable snapshot of data during the transaction -> Option DQuick Check:Transaction needed for stable cursor snapshot [OK]Quick Trick: Transaction ensures cursor sees consistent data [OK]Common Mistakes:Thinking cursors auto-commitBelieving cursors need exclusive locksAssuming cursors can't use SELECT outside transactions
Master "Advanced PL/pgSQL" in PostgreSQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PostgreSQL Quizzes Advanced Features - ENUM types - Quiz 9hard Advanced PL/pgSQL - Dynamic SQL with EXECUTE - Quiz 15hard Advanced PL/pgSQL - Why advanced PL/pgSQL matters - Quiz 13medium Advanced PL/pgSQL - Functions returning TABLE - Quiz 9hard Performance Tuning - Sequential scan vs index scan - Quiz 7medium Table Partitioning - Why partitioning is needed - Quiz 8hard Table Partitioning - Why partitioning is needed - Quiz 9hard Transactions and Concurrency - Read committed behavior - Quiz 9hard Transactions and Concurrency - Read committed behavior - Quiz 13medium Triggers in PostgreSQL - BEFORE trigger behavior - Quiz 15hard