Re: how to get the total number of records in report

Поиск
Список
Период
Сортировка
Искать
От
Merlin Moncure
Тема
Re: how to get the total number of records in report
Дата
Msg-id
AANLkTik+wEqEF=yWQrvYn6wN7YyJGoMtPu2-0jCTv+8F@mail.gmail.com
Ответ на
Список
Дерево обсуждения
how to get the total number of records in report AI Rumman <rummandba@gmail.com>
Re: how to get the total number of records in report Josh Kupershmidt <schmiddy@gmail.com>
Re: how to get the total number of records in report AI Rumman <rummandba@gmail.com>
Re: how to get the total number of records in report Greg Spiegelberg <gspiegelberg@gmail.com>
Re: how to get the total number of records in report Merlin Moncure <mmoncure@gmail.com>
Re: how to get the total number of records in report Robert Haas <robertmhaas@gmail.com>
Re: how to get the total number of records in report AI Rumman <rummandba@gmail.com>
Re: how to get the total number of records in report Merlin Moncure <mmoncure@gmail.com>
Re: how to get the total number of records in report Merlin Moncure <mmoncure@gmail.com>
On Mon, Oct 18, 2010 at 1:16 AM, AI Rumman  wrote:
> At present for reporting I use following types of query:
> select crm.*, crm_cnt.cnt
> from crm,
> (select count(*) as cnt from crm) crm_cnt;
> Here count query is used to find the total number of records.
> Same FROM clause is copied in both the part of the query.
> Is there any other good alternative way to get this similar value?

Probably the best way to do this type of thing is handle it on the
client.  However, if you want to do it this way and your from clause
is more complex than 'from table', you can possibly improve on this
with a CTE:

with q as (select * from )
select q.* q_cnt.cnt from q, (select count(*) as cnt from q) q_cnt;

The advantage here is that the CTE is materialized without having to
do the whole query again.  This can be win or loss depending on the
query.

merlin
В списке pgsql-performance по дате отправления
От: Ozer, Pam
Дата:
Сообщение: Re: Slow Query- Simple taking
От: Dimi Paun
Дата:
Сообщение: What is postmaster doing?
FAQ