pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow do I get column names?
3+ messages / 3 participants
[nested] [flat]
* How do I get column names?
@ 1999-12-13 20:30 Steven M. Wheeler <swheeler@sabre.com>
0 siblings, 2 replies; 3+ messages in thread
From: Steven M. Wheeler @ 1999-12-13 20:30 UTC (permalink / raw)
To: pgsql-sql@hub.org
A simple question.
What is the best way to query the DB, to get the column names for a particular table?
Thanks!
--
Steven Wheeler
Mid-Range UNIX Engineering
Sabre Inc.
(918) 292-4119
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] How do I get column names?
@ 1999-12-13 22:50 Tom Lane <tgl@sss.pgh.pa.us>
parent: Steven M. Wheeler <swheeler@sabre.com>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 1999-12-13 22:50 UTC (permalink / raw)
To: Steven M. Wheeler <swheeler@sabre.com>; +Cc: pgsql-sql@hub.org
"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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] How do I get column names?
@ 1999-12-14 01:13 neko@kredit.sth.szif.hu
parent: Steven M. Wheeler <swheeler@sabre.com>
1 sibling, 0 replies; 3+ messages in thread
From: neko@kredit.sth.szif.hu @ 1999-12-14 01:13 UTC (permalink / raw)
To: Steven M. Wheeler <swheeler@sabre.com>; +Cc: pgsql-sql@hub.org
On Mon, 13 Dec 1999, Steven M. Wheeler wrote:
> A simple question.
>
> What is the best way to query the DB, to get the column names for a
> particular table?
SELECT attname FROM pg_attribute, pg_class WHERE pg_class.oid = attrleid
AND attnum>0 AND relname = 'particular_table';
In this way, in each tuple of the result can find a column name.
Or can use the simple:
SELECT * FROM particular_table LIMIT 1;
This query will be return with a single line, and you can get the column
names from the result. (PQfname).
The first way may a bit faster, but the second can work with user typed
querys too.
Best Regards
--
nek;(
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~1999-12-14 01:13 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-12-13 20:30 How do I get column names? Steven M. Wheeler <swheeler@sabre.com>
1999-12-13 22:50 ` Tom Lane <tgl@sss.pgh.pa.us>
1999-12-14 01:13 ` neko@kredit.sth.szif.hu
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