From: | "Greg Sabino Mullane" <greg(at)turnstep(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Way to use count() and LIMIT? |
Date: | 2001-12-19 15:55:12 |
Message-ID: | E16Gj25-0005gq-00@granger.mail.mindspring.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> Simply ask the database for one more record that you're going to
> display. If you get that extra record, then display the next button,
> otherwise don't. The count is irrelevent
Great idea. If you are using DBI, you can even do a $sth->rows()
call to avoid the overhead of grabbing the data via a fetch.
(unless you are using fetchall/selectall)
Still, it seems that there should be a way to grab the information,
especially if you have an "ORDER BY" clause in your query - after
all, that means at some point, postgres knows how many records
matched before it ORDERS and LIMITS them.
Something like this:
SELECT pg_get_totalrows, artist, title, year
FROM giantcdcollection
WHERE genre = 'Rock'
ORDER BY artist, title
LIMIT 21
OFFSET 200
should be possible with no slow down of query time, I would think.
Inefficient in that it returns the same number 21 times, but
a bargain compared to the current way to do it (separate count query).
Greg Sabino Mullane
greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200112191051
-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html
iD8DBQE8ILggvJuQZxSWSsgRAny6AKCG/DrD2dhft6/kwjiHJ5a5jPwvFQCfeoHJ
Ej56nl3x5+snq9wynedCfUo=
=LFIM
-----END PGP SIGNATURE-----
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-12-19 17:13:25 | Re: Way to use count() and LIMIT? |
Previous Message | Lee Kindness | 2001-12-19 15:44:09 | Outputting select into file. |