Hi all.
This is not very "hackers"-related, but related to the topic of 
window-funcitons, which seems to be discussed quite a bit on "hackers" these 
days.

Can window-functions in PG be used to return "total number of rows" in a "paged 
result"?
Say you have:
SELECT p.id, p.firstname
  FROM person p
 ORDER BY p.firstname ASC
 LIMIT 10 OFFSET 10

Is it possible to use some window-function to return the "total-number of 
columns" in a separate column?

In Oracle one can do 
SELECT q.*, max(rownum) over() as total_rows FROM (subquery)
which returns the total number or columns in a separate column. This is very 
handy for web-pages which for example need to display the rist 20 results of 
several million, without having to do a separate count(*) query.

-- 
Andreas Joseph Krogh <[EMAIL PROTECTED]>
Senior Software Developer / CEO
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Karenslyst Allé 11      | know how to do a thing and to watch         |
PO. Box 529 Skøyen      | somebody else doing it wrong, without       |
0214 Oslo               | comment.                                    |
NORWAY                  |                                             |
Tlf:    +47 24 15 38 90 |                                             |
Fax:    +47 24 15 38 91 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to