Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.  The problem is that mucks with the order of the original query because of the sort on row_number.  I’ve even thought about reversing the order and then reversing the order a second time but that seems to be getting more than a little absurd.

Thank you for your time,
Perry

Attachment: signature.asc
Description: Message signed with OpenPGP


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux