pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: lynch@lscorp.com
To: Glenn Sullivan <glenn.sullivan@nmr.varian.com>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] Cursors
Date: Wed, 23 Sep 1998 15:09:15 -0500
Message-ID: <v02140b6cb22eb61f601e@[207.152.64.133]> (raw)

>I am new to Postgre (and databases), and just figuring how to
>use it.  I see numerous references to cursors, but I do not
>understand what they are for.  Could someone point me to someplace
>to read, or give me one paragraph to enlighten me.

Suppose you have a *HUGE* database.  Like Publisher's Clearinghouse you may
already have won a million dollars huge.  If you were going to look at it
on the web, you really, REALLY, *REALLY* don't want to do a query like:

"select * from losers order by lastname, firstname"

It's pretty much guaranteed to choke the machine, eh?  "Imminent Death of
the Internet, Film at 11."

So, you use a cursor.  A cursor allows you to select a specific range
within a large set of records, but also have order by and group by behave
properly.

By creating a cursor and using that cursor in a query, the result set can
be calculated by the backend, but only a tiny fraction of that set will be
transmitted to the the browser at one time.

The backend *MIGHT* even be really smart and not have to do the *WHOLE*
sort, before allowing you to get the first N records, but I dunno about
that for sure.

The details on how to use cursors in PostgreSQL are in the archives, so I
won't repeat them here.

Disclaimer:  Main because I dunno how to use them.  I've never had a db
that large. :-)

--
--
-- "TANSTAAFL" Rich lynch@lscorp.com





view thread (2+ messages)

Message-ID: <v02140b6cb22eb61f601e@[207.152.64.133]>
Permalink:  ../v02140b6cb22eb61f601e@%5B207.152.64.133%5D/
Also on:    postgresql.org/message-id/v02140b6cb22eb61f601e@[207.152.64.133]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: lynch@lscorp.com, glenn.sullivan@nmr.varian.com, pgsql-sql@hub.org
  Subject: Re: [SQL] Cursors
  In-Reply-To: <v02140b6cb22eb61f601e@[207.152.64.133]>
  References: <v02140b6cb22eb61f601e@[207.152.64.133]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox