On Thu, Sep 28, 2017 at 3:31 PM, Seamus Abshere <seamus@abshere.net> wrote:
> > > Does anybody have a function lying around (preferably pl/pgsql) that > > > takes a table name and returns coverage counts? > > > > What is "coverage count"?
Ah, I should have explained better. I meant how much of a column is null.
Basically you have to
0. count how many total records in a table 1. discover the column names in a table 2. for each column name, count how many nulls and subtract from total count
If nobody has one written, I'll write one and blog it.
I can't really do the full query for you, but the following should be able to give you a head start:
SELECT c.relname AS table, a.attname AS column, a.attnum AS colnum, s.stanullfrac as pct_null, s.stadistinct FROM pg_class c JOIN pg_attribute a ON a.attrelid = c.oid JOIN pg_statistic s ON (s.starelid = c.oid AND s.staattnum = a.attnum) WHERE c.relname = 'your_table_name' AND a.attnum > 0 ORDER BY 3
--
Melvin Davidson I reserve the right to fantasize. Whether or not you wish to share my fantasy is entirely up to you.