"Steven M. Wheeler" <swheeler@sabre.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