Thread: How can i get the column names?

How can i get the column names?

From
"freenet"
Date:
Hi,
For an aplication i need to get only the column names! 
I'm trying to select the column names from a table, but without success.
Can anybody instruct me how can i do it?
 
Thanks
Leo.

Re: How can i get the column names?

From
Martijn van Oosterhout
Date:
On Mon, Oct 28, 2002 at 01:57:04PM +0100, freenet wrote:
> Hi,
> For an aplication i need to get only the column names!
> I'm trying to select the column names from a table, but without success.
> Can anybody instruct me how can i do it?

$ psql -E db
db> \d

That should give you the queries you want.
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.

Attachment

Re: How can i get the column names?

From
"Shridhar Daithankar"
Date:
On 28 Oct 2002 at 13:57, freenet wrote:
> For an aplication i need to get only the column names!
> I'm trying to select the column names from a table, but without success.
> Can anybody instruct me how can i do it?

There are couple of ways..

1) If you are using C API, libpq allows you to retrieve field names given field
numbers and vice versa. You can use that.

2) You can query pg meta data. See if this query helps you..

select attrelid,attname from pg_attribute where attrelid=(select oid from
pg_class where relname='your table name');

Take a look at pg_attribute. The explanation is in manual under name of 'System
Catalogs;

 HTH



Bye
 Shridhar

--
Uncle Ed's Rule of Thumb:    Never use your thumb for a rule.    You'll either hit it
with a hammer or get a splinter in it.