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

Поиск
Список
Период
Сортировка
От Josh Williams
Тема Re: psql: what's the SQL to compute the ratio of table sizes?
Дата
Msg-id 1224273154.19453.7.camel@godzilla.local.scalefeather.com
обсуждение исходный текст
Ответ на psql: what's the SQL to compute the ratio of table sizes?  ("Kynn Jones" <kynnjo@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Aidan Van Dyk
Дата:
Сообщение: Re: Annoying Reply-To
Следующее
От: "Andrus"
Дата:
Сообщение: Optimizing queries with projected columns