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

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Can I get the number of results plus the results with a single query?
Date: 2022-08-17 09:26:34
Message-ID: 20220817092634.kp7atpc3zoqaovri@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2022-08-16 14:42:48 -0700, Bryn Llewellyn wrote:
> hjp-pgsql(at)hjp(dot)at wrote:
> The OP wants some kind of progress indicator. To be useful, such
> an indicator should be approximately linear in time. I.e. if your
[...]
>
>
> I see, Peter. You’d read the OP’s mind.

Not much mind-reading involved, I hope. The first sentence in the
message was:

| I like to have what I call “baby sitting” messages such as “Completed 15 out of 1023”.

That's what I would call a "progress indicator". Such things were
already common when I first got involved with computers almost 40 years
ago, so there isn't much to guess or to invent.

> But I’d failed to. I saw the subject, you I assumed that the OP wanted
> the entire result set together with the count of the results. (After
> all, there’s no inflexions of “page” in the OP’s question.)

I don't think his question was about paging. That's a different although
related topic.

> It sounds like the OP wants a fast approximate count for a query whose
> restriction isn’t known until runtime.

Maybe an approximate count would be enough, but he didn't say so.

(He did later clarify that he's fetching a lot of data for each row, so
«select count(*) ,,,» is indeed much faster than «select * ...» due to
the sheer amount of data to be transferred. That wasn't obvious from his
first message, but I hedged against the possibility in my answer.)

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message ajay venki 2022-08-17 09:32:26 Postgres question
Previous Message Rama Krishnan 2022-08-17 08:53:41 Sub:column "" is of type bigint but expression is of type character varying