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

From: Josh Williams <joshwilliams(at)ij(dot)net>
To: Kynn Jones <kynnjo(at)gmail(dot)com>
Cc: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql: what's the SQL to compute the ratio of table sizes?
Date: 2008-10-17 19:52:34
Message-ID: 1224273154.19453.7.camel@godzilla.local.scalefeather.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dave Coventry 2008-10-17 20:02:14 Re: Annoying Reply-To
Previous Message Aidan Van Dyk 2008-10-17 19:43:08 Re: Annoying Reply-To