getting the row count of a UNION query

Поиск
Список
Период
Сортировка
От Lonni J Friedman
Тема getting the row count of a UNION query
Дата
Msg-id AANLkTinr15efxtJM8n45PX1Gc9cNXDJ+VRv+c45+4kD_@mail.gmail.com
обсуждение исходный текст
Список pgsql-novice
Greetings,
I've got a bunch of tables with the same schema, that I'm accessing
via a UNION query.  However, I'd like to get the count of returned
rows from this query.  The best that I've been able to come up with at
this point is the following:
SELECT sum(counter) FROM ((select count(id) as counter from a0 ) UNION
ALL (select count(id) as counter from b0) UNION ALL (select count(id)
as counter from c0)) as foo;

From what I'm reading this is inefficient.  Is there a better way to
get the total row count without resorting to executing each of the
subqueries separately and summing their rows?

thanks!

В списке pgsql-novice по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Raw Device Support
Следующее
От: Mladen Gogala
Дата:
Сообщение: Re: Raw Device Support