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

Lists: pgsql-sql
From: "Steven M(dot) Wheeler" <swheeler(at)sabre(dot)com>
To: pgsql-sql(at)hub(dot)org
Subject: How do I get column names?
Date: 1999-12-13 20:30:07
Message-ID: 3855574F.3314738E@sabre.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

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


From: neko(at)kredit(dot)sth(dot)szif(dot)hu
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-14 01:13:12
Message-ID: Pine.LNX.4.10.9912140143180.5706-100000@kredit.sth.szif.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

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;(