Window Functions

Поиск
Список
Период
Сортировка
От Andreas Joseph Krogh
Тема Window Functions
Дата
Msg-id 200810141105.32218.andreak@officenet.no
обсуждение исходный текст
Ответы Re: Window Functions  (Hannu Krosing <hannu@2ndQuadrant.com>)
Список 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 по дате отправления:

Предыдущее
От: KaiGai Kohei
Дата:
Сообщение: Updates of SE-PostgreSQL 8.4devel patches (r1120)
Следующее
От: Dave Cramer
Дата:
Сообщение: log shipping pg_standby