Re: Show table and columns with null value and count

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Zied Kharrat <khzied(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Show table and columns with null value and count
Date: 2021-08-05 14:38:46
Message-ID: CAKFQuwbK=4FKvDXgrtWA3BeEpsCbzF4zQUxwFDmErpv8WsQ2gg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Aug 5, 2021 at 7:09 AM Zied Kharrat <khzied(at)gmail(dot)com> wrote:

> I have a table which contains many data.
> I want to execute an sql request to show for every table, the name of the
> column, how many null value in this column, and total number of rows in
> this column.
> Could you help me?
>

If you need an exact number you will need to write some dynamic SQL using
the system catalogs to take inventory of the tables and columns in the
database.

If you can live with estimates you can simply query the statistics that are
kept by the system that it uses during query planning:
https://www.postgresql.org/docs/current/catalog-pg-statistic.html

David J.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rockdale Green 2021-08-05 16:53:25 Re: How to generate the order if you know the next item for each item?
Previous Message Tony Shelver 2021-08-05 14:33:36 Re: How to generate the order if you know the next item for each item?