Pratika Rana Pratika Rana - 1 year ago 126
SQL Question

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

With the following query, we can get a list of column names and datatype of a table in PostgreSQL.

Answer Source
        a.attname as "Column",
        pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
        pg_catalog.pg_attribute a
        a.attnum > 0
        AND NOT a.attisdropped
        AND a.attrelid = (
            SELECT c.oid
            FROM pg_catalog.pg_class c
                LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
            WHERE c.relname ~ '^(hello world)$'
                AND pg_catalog.pg_table_is_visible(c.oid)

Change the hello world with your table name

More info on it :

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download