List all columns in specific table in PostgreSQL database

Query below returns a list of all columns in a specific table in PostgreSQL.


select ordinal_position as position,
       case when character_maximum_length is not null
            then character_maximum_length
            else numeric_precision end as max_length,
       column_default as default_value
from information_schema.columns
where table_name = 'Table name' -- enter table name here
      -- and table_schema= 'Schema name'
order by ordinal_position;


  • position - column position in table, starting at 1
  • column_name - name of a column in a table
  • data_type - column data type
  • max_length - data type max length
  • is_nullable - if column is nullable then YES, else NO
  • column_default - Default expression of the column


  • One row represents a single column
  • Scope of rows: represent all columns in a named table
  • Ordered by column's ordinal position

Sample results

You could also get this

Get this interactive HTML data dictionary in minutes with Dataedo.

See live HTML data dictionary sample

Try for free

There are no comments. Click here to write the first comment.