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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] How do I get column names?
Дата
Msg-id 12856.945125447@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How do I get column names?  ("Steven M. Wheeler" <swheeler@sabre.com>)
Ответы System Attribute  (Drew Whittle <drew@albatross.co.nz>)
Список pgsql-sql
"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


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Steven M. Wheeler"
Дата:
Сообщение: How do I get column names?
Следующее
От: Drew Whittle
Дата:
Сообщение: System Attribute