zakaria mouqcit
zakaria mouqcit

Reputation: 393

Select columns with null values postgresql

I'm working on a postgreSQL database with 22 table. I need a query which returns the columns with null values. May be a static sql statement that I can launch to each table.

I would be pleased to get some help.

Best.

Upvotes: 1

Views: 1900

Answers (1)

Michel Milezzi
Michel Milezzi

Reputation: 11105

Assuming that you run VACUUM ANALYZE periodically, pg_stats.null_frac can help you to get that:

--Get columns "filled" entirely with null values
SELECT 
    schemaname,
    tablename,
    attname,
    null_frac 
FROM 
    pg_stats 
WHERE 
    null_frac = 1.0 
    AND schemaname = 'yourschema'

Upvotes: 2

Related Questions