Re: Count of non-null values per table column

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Count of non-null values per table column
Дата
Msg-id 4333.1439564459@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Count of non-null values per table column  (David Rowley <david.rowley@2ndquadrant.com>)
Ответы Re: Count of non-null values per table column
Список pgsql-general
David Rowley <david.rowley@2ndquadrant.com> writes:
> On 15 August 2015 at 02:32, David Nelson <dlnelson77808@outlook.com> wrote:
>> Hello list,<br><br>Apologies if this has been asked before. My search only
>> turned up ways to list the total non-null values for all columns as a
>> single number. I want the count for each column by column.

> I assume the tables are quite large if you don't want to just issue a:
> SELECT COUNT(a) FILTER(WHERE a IS NULL),COUNT(b) FILTER(WHERE b IS NULL)
> ... (assuming you're on a version new enough to support agg FILTER)

AFAIK this should work in any version, or indeed any SQL-compliant DBMS:

      select count(col1), count(col2), ... from table;

COUNT with an argument counts the non-null values of that argument.

> On the other hand if you were happy with just an approximation then you
> could look at pg_stats;

Yeah; you might want to ANALYZE the table first to be sure the stats are
up to date.

            regards, tom lane


В списке pgsql-general по дате отправления:

Предыдущее
От: John McKown
Дата:
Сообщение: Re: Count of non-null values per table column
Следующее
От: Sachin Srivastava
Дата:
Сообщение: Re: PostgreSQL - The Best Overall Database