From: Wim Bertels <wim.bertels@ucll.be>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Can I get the number of results plus the results with a single query?
Date: Mon, 22 Aug 2022 07:17:09 +0000
Message-ID: <c26e951ed0b6074536deef1a94f2a0b30c35f506.camel@ucll.be> (raw)
In-Reply-To: <75BBE3C5-D495-47B8-A81C-6359391E3B99@easesoftware.com>
References: <75BBE3C5-D495-47B8-A81C-6359391E3B99@easesoftware.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: wim.bertels@ucll.be
Subject: Re: Can I get the number of results plus the results with a single query?
In-Reply-To: <c26e951ed0b6074536deef1a94f2a0b30c35f506.camel@ucll.be>
References: <75BBE3C5-D495-47B8-A81C-6359391E3B99@easesoftware.com> <c26e951ed0b6074536deef1a94f2a0b30c35f506.camel@ucll.be>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox