From: Tom Lane <tgl@sss.pgh.pa.us>
To: Steven M. Wheeler <swheeler@sabre.com>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] How do I get column names?
Date: Mon, 13 Dec 1999 17:50:47 -0500
Message-ID: <12856.945125447@sss.pgh.pa.us> (raw)
In-Reply-To: <3855574F.3314738E@sabre.com>
"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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, swheeler@sabre.com, pgsql-sql@hub.org
Subject: Re: [SQL] How do I get column names?
In-Reply-To: <12856.945125447@sss.pgh.pa.us>
References: <3855574F.3314738E@sabre.com> <12856.945125447@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox