Re: about cursors

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ottavio Campana <ottavio(at)campana(dot)vi(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: about cursors
Date: 2007-06-16 17:24:05
Message-ID: 12401.1182014645@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ottavio Campana <ottavio(at)campana(dot)vi(dot)it> writes:
> Postgresql doc says "a cursor that encapsulates the query, and then read
> the query result a few rows at a time." So, when I open a cursor, is all
> the query executed

No, just enough to give you the rows you ask for. Otherwise the query
state is held open until the next FETCH.

Exception: if you declare a cursor WITH HOLD then it's executed to
completion before the transaction commits, because the resources
involved in an open query (eg locks) can't be kept across transactions.

Also, depending on how complex the query is, the system might have to do
most of the work before it can deliver even the first row. ORDER BY
implemented by an explicit sort step is like that, for example.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Allison 2007-06-16 17:56:00 Re: Using the GPU
Previous Message Joshua D. Drake 2007-06-16 17:07:39 Re: PHP sucks!! - was: persistent db connections in PHP