Re: Can I get the number of results plus the results with a single query? - Mailing list pgsql-general

From Wim Bertels
Subject Re: Can I get the number of results plus the results with a single query?
Date
Msg-id c26e951ed0b6074536deef1a94f2a0b30c35f506.camel@ucll.be
Whole thread Raw
In response to Can I get the number of results plus the results with a single query?  (Perry Smith <pedz@easesoftware.com>)
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: Support for dates before 4713 BC
Next
From: "sivapostgres@yahoo.com"
Date:
Subject: Re: Creating constraint dynamically