Average number of columns per table in PostgreSQL database

Query below returns the average number of columns per table in a database.


select count(*) as columns,
       count(distinct t.table_schema || '.' || t.table_name) as tables,
       round ((count(*)::decimal
            / count(distinct t.table_schema || '.' || t.table_name)), 2)
        as average_column_count
from information_schema.tables t
left join information_schema.columns c on c.table_schema = t.table_schema
          and c.table_name = t.table_name
where t.table_schema not in ('information_schema', 'pg_catalog')
      and table_type = 'BASE TABLE';


  • columns - total number of columns in a database
  • tables - number of tables in a database
  • average_column_count - average number of columns in a table in a database


  • Query returns just one row

Sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
There are no comments. Click here to write the first comment.