Can I get the number of results plus the results with a single query?

Поиск
Список
Период
Сортировка
От Perry Smith
Тема Can I get the number of results plus the results with a single query?
Дата
Msg-id 75BBE3C5-D495-47B8-A81C-6359391E3B99@easesoftware.com
обсуждение исходный текст
Ответы Re: Can I get the number of results plus the results with a single query?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Can I get the number of results plus the results with a single query?  ("Peter J. Holzer" <hjp-pgsql@hjp.at>)
Re: Can I get the number of results plus the results with a single query?  (Wim Bertels <wim.bertels@ucll.be>)
Список pgsql-general
I like to have what I call “baby sitting” messages such as “Completed 15 out of 1023”.  To do this, I need the number
ofresults a query returns but I also need the results. 

Currently I’m doing this with two queries such as:

    SELECT COUNT(*) FROM table WHERE …. expression …
    SELECT * FROM table WHERE …. expression …

But this requires two queries.  Is there a way to do the same thing with just one query somehow?

I’ve been toying with row_number() and then sort by row_number descending and pick off the first row as the total
number. The problem is that mucks with the order of the original query because of the sort on row_number.  I’ve even
thoughtabout reversing the order and then reversing the order a second time but that seems to be getting more than a
littleabsurd. 

Thank you for your time,
Perry


Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Gaurav Daunde
Дата:
Сообщение: Help regarding Multi Tenancy with PostgreSQL
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Can I get the number of results plus the results with a single query?