Check for null columns in a table I have a table which has more than 200 columns, I want to check if any of the column is having only null/ blank values in the entire table. I tried to do it using

SELECT 'SELECT ' || STRING_AGG(   'max("'
                               || column_name
                               || '") "'
                               || column_name
                               || '"',
                               ',')
                 || ' FROM &lt;table name&gt;;'
  FROM information_schema.columns
 WHERE table_name='&lt;table name&gt;';


From here, it will give me max values of a column, and I understand that columns with values null is what I am looking for, but question is how do I display that. I am using PostgreSQL DB.
From the wording of your question, I guess something like:

SELECT substr(agg_stmt,1,LENGTH(agg_stmt)-10) FROM (
    SELECT STRING_AGG(stmt, '') as agg_stmt FROM (
        SELECT 'SELECT ' || '''' || column_name 
            || ''' as col, COUNT(NULLIF(' || column_name || ','''')) as cnt FROM ' 
            || table_name || '' || ' union all ' as stmt
        FROM information_schema.columns
        WHERE table_name = 't'
    ) AS TT
) AS TTT;


should do. For a table T (x, y) it will generate a stmt like:

SELECT 'x' as col, COUNT(NULLIF(x,'')) as cnt FROM t union all SELECT 'y' as col, COUNT(NULLIF(y,'')) as cnt FROM t


You can add an outer stmt like:

SELECT col FROM (
    SELECT 'x' as col, COUNT(NULLIF(x,'')) as cnt FROM t 
    union all 
    SELECT 'y' as col, COUNT(NULLIF(y,'')) as cnt FROM t
) AS Q
WHERE cnt = 0


to get all columns that have only null or ''