From: | Andreas Joseph Krogh <andreak(at)officenet(dot)no> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Window Functions |
Date: | 2008-10-14 09:05:32 |
Message-ID: | 200810141105.32218.andreak@officenet.no |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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 <andreak(at)officenet(dot)no>
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 | |
------------------------+---------------------------------------------+
From | Date | Subject | |
---|---|---|---|
Next Message | Vladimir Sitnikov | 2008-10-14 09:23:22 | Re: 8.3 .4 + Vista + MingW + initdb = ACCESS_DENIED |
Previous Message | Dave Page | 2008-10-14 08:49:30 | Re: 8.3 .4 + Vista + MingW + initdb = ACCESS_DENIED |