Search Postgresql Archives

Re: psql: what's the SQL to compute the ratio of table sizes?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2008-10-17 at 15:30 -0400, Kynn Jones wrote:
> Suppose I have two table X and Y and I want to compute the ratio of
> the number of rows in X and the number of rows in Y.  What would be
> the SQL I could type into a psql session to get this number?

Sub-selects should work.  And make sure to cast to avoid integer
division (well, assuming you want to avoid it...)

SELECT (SELECT COUNT(*) FROM tablex)::numeric / (SELECT COUNT(*) FROM
tabley)::numeric AS ratio;

- Josh Williams



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux