Re: [SQL] How do I get column names?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Steven M(dot) Wheeler" <swheeler(at)sabre(dot)com>
Cc: pgsql-sql(at)hub(dot)org
Subject: Re: [SQL] How do I get column names?
Date: 1999-12-13 22:50:47
Message-ID: 12856.945125447@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Steven M. Wheeler" <swheeler(at)sabre(dot)com> writes:
> What is the best way to query the DB, to get the column names for a
> particular table?

Usually you'd join across pg_attribute and pg_class, assuming that you
were starting from a table name. For example:

regression=> select attname, attnum from pg_attribute, pg_class where
regression-> attrelid = pg_class.oid and relname = 'int8_tbl';
attname|attnum
-------+------
cmax | -6
xmax | -5
cmin | -4
xmin | -3
oid | -2
ctid | -1
q1 | 1
q2 | 2
(8 rows)

You probably would also want 'and attnum > 0' in the where-clause to
exclude the system attributes...

regards, tom lane

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Drew Whittle 1999-12-14 00:14:14 System Attribute
Previous Message Steven M. Wheeler 1999-12-13 20:30:07 How do I get column names?