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

From: Steve Atkins <steve(at)blighty(dot)com>
To: 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 21:32:54
Message-ID: 9D4837EC-0529-4F0A-AC83-9E7E9FE2A67E@blighty.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Oct 17, 2008, at 12:30 PM, 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?
>
> This is an example of the recurring problem of performing arithmetic
> using the result of various calls to count(*) (or other mathematic
> functions).

select (select count(*)::float from X) / (select count(*)::float from
Y);

count(*) may take a while on large tables; there are other options if
you'd prefer something fast and approximate.

Cheers,
Steve

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kynn Jones 2008-10-17 21:38:22 Re: psql: what's the SQL to compute the ratio of table sizes?
Previous Message Brian Modra 2008-10-17 21:19:28 ideal server