Re: psql: what's the SQL to compute the ratio of table sizes? - Mailing list pgsql-general

From Josh Williams
Subject Re: psql: what's the SQL to compute the ratio of table sizes?
Date
Msg-id 1224273154.19453.7.camel@godzilla.local.scalefeather.com
Whole thread Raw
In response to psql: what's the SQL to compute the ratio of table sizes?  ("Kynn Jones" <kynnjo@gmail.com>)
List pgsql-general
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



pgsql-general by date:

Previous
From: Aidan Van Dyk
Date:
Subject: Re: Annoying Reply-To
Next
From: "Andrus"
Date:
Subject: Optimizing queries with projected columns