How to find all columns of a table in PostgreSQL

In this article, we will see how to find all columns of a table in PostgreSQL.

A postgresql table not only contains user defined columns. It also adds column names like xmin, xmax,….

Find the all column names:

1. We can get the user defined column names and datatypes using below command:

\d+ foo.bar

How to find all columns of a table in PostgreSQL

2. If we want all column names including hidden column names in PostgreSQL, run the below query against pg_attribute.

SELECT attname, format_type (atttypid,atttypmod) FROM pg_attribute WHERE attrelid = 'foo.bar'::regclass::oid ORDER BY attnum;

Here, except id and name remaining are system columns.