Re: Count of non-null values per table column - Mailing list pgsql-general

From David Nelson
Subject Re: Count of non-null values per table column
Date
Msg-id COL126-W3799A33B6369CDCDE76578F17C0@phx.gbl
Whole thread Raw
In response to Count of non-null values per table column  (David Nelson <dlnelson77808@outlook.com>)
Responses Re: Count of non-null values per table column
List pgsql-general
Well it is certainly nice to see that my choice to send my question using plain text was honored by this email service.
Apologiesfor that mess. The output I am looking for is a series of rows with two columns, one the name of the table
column,and the other the count of non-null values in a table's column of that same name, for all column names in the
table.<br><br>Thanks<br><br>----------------------------------------<br>>From: dlnelson77808@outlook.com<br>> To:
pgsql-general@postgresql.org<br>>Subject: [GENERAL] Count of non-null values per table column<br>> Date: Fri, 14
Aug2015 14:32:36 +0000<br>><br>> Hello list,<br><br>Apologies if this has been asked before. My
searchonly turned up ways to list the total non-null values for all columns as a single number. I want the count for
eachcolumn by column.<br><br>I have inherited a database consisting of two related huge monolithic tables
thatlack referential integrity between them, or even basic data constraints. One of the problems these tables have is
everysingle non-PK column is NULLable. I am trying to understand the information that is actually stored and used so
thatI can implement a (hopefully) better design. Towards that end I would like to know the count of non-null values in
eachcolumn per column. In other words I would like to get the following output from a table (the numbers are totally
madeup):<br><br>column_name |
num_values<br>------------+-----------<br>col1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
5787<br>------------+-----------<br>col2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
17<br>------------+-----------<br>col3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
567<br>------------+-----------<br>col4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
5787<br>------------+-----------<br>col5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
143<br>------------+-----------<br>col6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1<br>------------+-----------<br>...<br><br>Isthis possible through one or more of the system
views,or will I need to write a function to do this? Obviously I can just issue multiple SELECT COUNT(column)...
statements,but I'd rather not.<br><br>Thanks,<br>David<br>><br>> --<br>> Sent via
pgsql-generalmailing list (pgsql-general@postgresql.org)<br>> To make changes to your subscription:<br>>
http://www.postgresql.org/mailpref/pgsql-general<br>                           

pgsql-general by date:

Previous
From: David Nelson
Date:
Subject: Count of non-null values per table column
Next
From: David Rowley
Date:
Subject: Re: Count of non-null values per table column