about cursors

From: Ottavio Campana <ottavio(at)campana(dot)vi(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: about cursors
Date: 2007-06-16 16:58:27
Message-ID: 467416B3.1010601@campana.vi.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I never used cursors before, and I'm trying to understand how to use
them well.

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 and results are returned a few a time?

My doubt comes from
http://archives.postgresql.org/pgsql-sql/2005-08/msg00230.php where I
read "when you open a cursor PostgreSQL doesn't know how many
rows it will return". So I start thinking that maybe it does not execute
the whole query....

At this point I'm not able to understand any more if cursor are useful
to reduce computational needs compared to running the same query each
time with limit and offset.

One last question: what happens to unclosed cursors? I mean, suppose an
application opens a cursor and crashes. What happens to that cursor? Is
there a way to close idle cursors?

Thanks.

--
Non c'e' piu' forza nella normalita', c'e' solo monotonia.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-06-16 17:07:39 Re: PHP sucks!! - was: persistent db connections in PHP
Previous Message PFC 2007-06-16 16:24:23 Re: PHP sucks!! - was: persistent db connections in PHP