Re: Cursors and Transactions, why? - Mailing list pgsql-general

From Joe Conway
Subject Re: Cursors and Transactions, why?
Date
Msg-id 4071E163.40602@joeconway.com
Whole thread Raw
In response to Cursors and Transactions, why?  (Eric Ridge <ebr@tcdi.com>)
List pgsql-general
Eric Ridge wrote:
> Why must a cursor be defined in an open transaction?  Obviously there's
> a good reason, but I can't figure it out.  On a high level, what would
> be involved in allowing a cursor to outlive the transaction that created
> it?

Historically I think it was because the memory was released at the end
of the current transaction (i.e. allocations were made in
TopTransactionContext). But as of 7.4, cursors *can* outlive transactions:
http://www.postgresql.org/docs/current/interactive/sql-declare.html

WITH HOLD
WITHOUT HOLD

     WITH HOLD specifies that the cursor may continue to be used after
the transaction that created it successfully commits. WITHOUT HOLD
specifies that the cursor cannot be used outside of the transaction that
created it. If neither WITHOUT HOLD nor WITH HOLD is specified, WITHOUT
HOLD is the default.

HTH,

Joe


pgsql-general by date:

Previous
From: Eric Ridge
Date:
Subject: Re: Cursors and Transactions, why?
Next
From: Tom Lane
Date:
Subject: Re: left and overleft/notright revisited: why !>> and !<< might be poor names