Count of non-null values per table column
От | David Nelson |
---|---|
Тема | Count of non-null values per table column |
Дата | |
Msg-id | COL126-W17C3CB6C83A930359CC7FDF17C0@phx.gbl обсуждение исходный текст |
Ответы |
Re: Count of non-null values per table column
Re: Count of non-null values per table column |
Список | pgsql-general |
Hello list,<br><br>Apologies if this has been asked before. My search only turned up ways to list the total non-null valuesfor all columns as a single number. I want the count for each column by column.<br><br>I have inherited a databaseconsisting of two related huge monolithic tables that lack referential integrity between them, or even basic dataconstraints. One of the problems these tables have is every single non-PK column is NULLable. I am trying to understandthe information that is actually stored and used so that I can implement a (hopefully) better design. Towards thatend I would like to know the count of non-null values in each column per column. In other words I would like to get thefollowing output from a table (the numbers are totally made up):<br><br>column_name | num_values<br>------------+-----------<br>col1 | 5787<br>------------+-----------<br>col2 | 17<br>------------+-----------<br>col3 | 567<br>------------+-----------<br>col4 | 5787<br>------------+-----------<br>col5 | 143<br>------------+-----------<br>col6 | 1<br>------------+-----------<br>...<br><br>Is this possible throughone or more of the system views, or will I need to write a function to do this? Obviously I can just issue multipleSELECT COUNT(column)... statements, but I'd rather not.<br><br>Thanks,<br>David
В списке pgsql-general по дате отправления: