getting the row count of a UNION query - Mailing list pgsql-novice

From Lonni J Friedman
Subject getting the row count of a UNION query
Date
Msg-id AANLkTinr15efxtJM8n45PX1Gc9cNXDJ+VRv+c45+4kD_@mail.gmail.com
Whole thread Raw
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: Raw Device Support
Next
From: Mladen Gogala
Date:
Subject: Re: Raw Device Support