How to get a list column names and datatypes of a table in PostgreSQL?

How can I get a list of column names and datatypes of a table in PostgreSQL using a query?


Solution 1:

Open psql command line and type :

\d+ table_name

Solution 2:

SELECT
    column_name,
    data_type
FROM
    information_schema.columns
WHERE
    table_name = 'table_name';

with the above query you can columns and its datatype