Received: from lscorp.com (poohbah.lscorp.com [207.152.64.2]) by hub.org (8.8.8/8.8.8) with ESMTP id QAA15766 for ; Wed, 23 Sep 1998 16:11:05 -0400 (EDT) (envelope-from lynch@lscorp.com) Received: from [207.152.64.133] by lscorp.com with SMTP (Eudora Internet Mail Server 1.2); Wed, 23 Sep 1998 15:09:15 -0500 X-Sender: lynch@poohbah.lscorp.com Message-Id: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: Glenn Sullivan From: lynch@lscorp.com (Richard Lynch) Subject: Re: [SQL] Cursors Cc: pgsql-sql@hub.org Date: Wed, 23 Sep 1998 15:09:15 -0500 >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