Search Postgresql Archives

Re: Count of non-null values per table column

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well it is certainly nice to see that my choice to send my question using plain text was honored by this email service. Apologies for 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>&gt; From: dlnelson77808@xxxxxxxxxxx<br>&gt; To: pgsql-general@xxxxxxxxxxxxxx<br>&gt; Subject:  Count of non-null values per table column<br>&gt; Date: Fri, 14 Aug 2015 14:32:36 +0000<br>&gt;<br>&gt; Hello list,&lt;br&gt;&lt;br&gt;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.&lt;br&gt;&lt;br&gt;I have inherited a database consisting of two related huge monolithic tables that lack referential integrity between them, or even basic data constraints. One of the problems these tables have is every single non-PK column is NULLable. I am trying to understand the information that is actually stored and used so that I can implement a (hopefully) better design. Towards that end I would like to know the count of non-null values in each column per column. In other words I would like to get the following output from a table (the numbers are totally made up):&lt;br&gt;&lt;br&gt;column_name | num_values&lt;br&gt;------------+-----------&lt;br&gt;col1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5787&lt;br&gt;------------+-----------&lt;br&gt;col2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17&lt;br&gt;------------+-----------&lt;br&gt;col3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 567&lt;br&gt;------------+-----------&lt;br&gt;col4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5787&lt;br&gt;------------+-----------&lt;br&gt;col5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 143&lt;br&gt;------------+-----------&lt;br&gt;col6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;br&gt;------------+-----------&lt;br&gt;...&lt;br&gt;&lt;br&gt;Is this 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.&lt;br&gt;&lt;br&gt;Thanks,&lt;br&gt;David<br>&gt;<br>&gt; --<br>&gt; Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)<br>&gt; To make changes to your subscription:<br>&gt; http://www.postgresql.org/mailpref/pgsql-general<br> 		 	   		  

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux