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

Поиск
Список
Период
Сортировка
От Wim Bertels
Тема Re: Can I get the number of results plus the results with a single query?
Дата
Msg-id c26e951ed0b6074536deef1a94f2a0b30c35f506.camel@ucll.be
обсуждение исходный текст
Ответ на Can I get the number of results plus the results with a single query?  (Perry Smith <pedz@easesoftware.com>)
Список pgsql-general
Perry Smith schreef op ma 15-08-2022 om 08:49 [-0500]:
> I like to have what I call “baby sitting” messages such as “Completed
> 15 out of 1023”.  To do this, I need the number of results 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.  

if i understand your question:

count(*) over ()

(u can use aggregate functions as well, not only window functions)



mvg,
Wim

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Support for dates before 4713 BC
Следующее
От: "sivapostgres@yahoo.com"
Дата:
Сообщение: Re: Creating constraint dynamically