Window Functions - Mailing list pgsql-hackers

From Andreas Joseph Krogh
Subject Window Functions
Date
Msg-id 200810141105.32218.andreak@officenet.no
Whole thread Raw
Responses Re: Window Functions
List 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
biton "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 pORDER BY p.firstname ASCLIMIT 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
todisplay the rist 20 results of several million, without having to do a separate count(*) query. 

--
Andreas Joseph Krogh <andreak@officenet.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 |                                             |
------------------------+---------------------------------------------+


pgsql-hackers by date:

Previous
From: KaiGai Kohei
Date:
Subject: Updates of SE-PostgreSQL 8.4devel patches (r1120)
Next
From: Dave Cramer
Date:
Subject: log shipping pg_standby