Re: Getting list of columns in a table - Mailing list pgsql-general

From Jason Earl
Subject Re: Getting list of columns in a table
Date
Msg-id 87lm5z9j5w.fsf@npa01zz001.simplot.com
Whole thread Raw
In response to Getting list of columns in a table  (Mike Blackwell <mblackwell@wallace.com>)
List pgsql-general
The trick is to fire up psql with -E flag.  That causes psql to spit
out the SQL it uses to query the system tables for things like:

\d tablename

I believe that the query you need is:

SELECT a.attname
FROM pg_class c, pg_attribute a
WHERE c.relname = 'schedule'
  AND a.attnum > 0 AND a.attrelid = c.oid
ORDER BY a.attnum;

Jason


Mike Blackwell <mblackwell@wallace.com> writes:

> Sorry if this is a FAQ, but didn't see it in the web site FAQ or in the
> docs I have.
>
> I need a SQL statement which will return a list of the column names for
> a (possibly empty) table.  FWIW, I'm using Perl and DBI.
>
> TiA,
> Mike
> mblackwell@wallace.com
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

pgsql-general by date:

Previous
From: Mike Blackwell
Date:
Subject: Getting list of columns in a table
Next
From: Jeff Boes
Date:
Subject: Database uptime?