Are queries run completely before a Cursor can be used? - Mailing list pgsql-general

From Seref Arikan
Subject Are queries run completely before a Cursor can be used?
Date
Msg-id CA+4Thdo7HRrW62F6f69Na7xLxEqqXxLHuCA_-f5ircNiW4aVFw@mail.gmail.com
Whole thread Raw
Responses Re: Are queries run completely before a Cursor can be used?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Greetings,
The documentation for Cursors at http://www.postgresql.org/docs/9.2/static/plpgsql-cursors.html says that:

"Rather than executing a whole query at once, it is possible to set up a cursor that encapsulates the query, and then read the query result a few rows at a time. One reason for doing this is to avoid memory overrun when the result contains a large number of rows"

I'm assuming the memory overrun mentioned here is the memory of the client process connecting to postres. I think when a cursor ref is returned, say from a function, the query needs to be completed and the results must be ready for the cursor to move forward.

If that is the case, there must be a temporary table, presumably with one or more parameters to adjust its size, (location/tablespace?) etc..

Is this how cursors work internally? I can't imagine the complexity of managing cursor operations in anything other than extremely simple sql queries.

Any comments and/or pointers to documentation which explains this would be much appreciated.

Best regards
Seref

pgsql-general by date:

Previous
From: "Vasudevan, Ramya"
Date:
Subject: Re: event triggers in 9.3.4
Next
From: Tom Lane
Date:
Subject: Re: Are queries run completely before a Cursor can be used?