Re: Count of non-null values per table column

From: John McKown <john(dot)archie(dot)mckown(at)gmail(dot)com>
To: David Nelson <dlnelson77808(at)outlook(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Count of non-null values per table column
Date: 2015-08-14 14:59:44
Message-ID: CAAJSdjh-YvR0r8P5Ctespf7JXqEXrm3o=etGhOnEUo9cBWsCBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David,

It still came through as junk. But I reconstructed it below

=== original message ===
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 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):

column_name | num_values
------------+-----------
col1 | 5787
------------+-----------
col2 | 17
------------+-----------
col3 | 567
------------+-----------
col4 | 5787
------------+-----------
col5 | 143
------------+-----------
col6 | 1
------------+-----------

====

​I assume what "num_values" contains is the _distinctly different_ number
of values in "column_name" for each and every column name in a table.​ E.g.
if "col1" contains value 'x' twice and 'y' ten times,then "num_values"
would be 2, not 12. Or do you really want the 12? I'm unsure.

--

Schrodinger's backup: The condition of any backup is unknown until a
restore is attempted.

Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be.

He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! <><
John McKown

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2015-08-14 15:00:59 Re: Count of non-null values per table column
Previous Message David Rowley 2015-08-14 14:51:57 Re: Count of non-null values per table column