Re: [GENERAL] Row Count?

From: Thomas Reinke <reinke(at)e-softinc(dot)com>
To: Bruce Tong <zztong(at)laxmi(dot)ev(dot)net>
Cc: PostgreSQL General <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] Row Count?
Date: 1999-05-05 16:21:52
Message-ID: 37307020.62DF25F@e-softinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bruce Tong wrote:
>
> > > SELECT * FROM foo WHERE ROW_COUNT < 10;
> > > Is there anything like "ROW_COUNT" or "ROWCOUNT" in PostgreSQL?
>
> > If trying to receive 10 rows, try
> >
> > begin;
> > declare thomas cursor for select * from foo;
> > fetch 10 in thomas;
> > end;
>
> Ooo, a cursor. I'll have to look into those. I was thinking I could just
> issue "select * from foo" and then only use the first 10 results, but that
> seemed like such a waste of time since there's likely to be 100's of
> records. Admittedly I'm ignorant of the solution you pose and I'll have to
> do some research, but it seems it too might also have the postmaster
> return all of the records, of which I would only use 10. Am I wrong?

Yes. It is designed explicitly for the purpose of limiting the returns.
For example, if you have a database of several million records and
want only 10 to be returned...

For example, a piece of code that wanted to be conservative on memory
usage, while handling millions of records in the database, might issue
(pseudo-code):

begin;
declare thomas cursor for select * from foo;
do
res = fetch 10 in thomas;
iRows = nTuples(res)
process_records;
while(iRows>0);
end;

>From a coding perspective, you deal with the results of the fetch just
as if they had come from the select.

Hope this helps

Thomas
>
> Bruce Tong | Got me an office; I'm there late at night.
> Systems Programmer | Just send me e-mail, maybe I'll write.
> Electronic Vision / FITNE |
> zztong(at)laxmi(dot)ev(dot)net | -- Joe Walsh for the 21st Century

--
------------------------------------------------------------
Thomas Reinke Tel: (416) 460-7021
Director of Technology Fax: (416) 598-2319
E-Soft Inc. http://www.e-softinc.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael J Davis 1999-05-05 16:26:29 unsubscribe problems
Previous Message Wim Ceulemans 1999-05-05 16:11:04 Re: [GENERAL] Row Count?