Re: about cursors - Mailing list pgsql-general

From Tom Lane
Subject Re: about cursors
Date
Msg-id 12401.1182014645@sss.pgh.pa.us
Whole thread Raw
In response to about cursors  (Ottavio Campana <ottavio@campana.vi.it>)
List pgsql-general
Ottavio Campana <ottavio@campana.vi.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

pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: PHP sucks!! - was: persistent db connections in PHP
Next
From: Tom Allison
Date:
Subject: Re: Using the GPU