1

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.

4
  • Are you looking for dynamic SQL here? Can you post your database information? Also, by "database" did you really mean "table?" Commented May 18, 2018 at 11:19
  • 3
    Try with WHERE col1 IS NULL... Commented May 18, 2018 at 11:26
  • I need one query which returns all the null columns of one table Commented May 18, 2018 at 11:30
  • postgresql.org/docs/10/static/… Commented May 18, 2018 at 11:34

1 Answer 1

2

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'
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for you response it does give the columns with null values. If it's possible I want to know if there is a possibility to have the count of these null values per each column?
You could multiply pg_stats.null_frac by pg_stat_user_tables.n_live_tup to get an estimative.
I did it but doesn't give any result!
@zakariamouqcit please create another question so we could help you there
solved the issue, thank you for your assistance and help.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.