Re: find column names from query - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: find column names from query
Date
Msg-id 20050124084241.GA40343@winnie.fuhr.org
Whole thread Raw
In response to find column names from query  (Afton & Ray Still <rastill@shaw.ca>)
List pgsql-novice
On Sun, Jan 23, 2005 at 11:46:15PM -0700, Afton & Ray Still wrote:

> going through the documentation I found the following:
>
> SELECT attname::regclass FROM pg_attribute WHERE attrelid = travel::regclass

Are you sure the example looked like that?  attname is a name type
and shouldn't be cast to regclass, and "travel" should be in single
quotes if it's a table name.  Try this:

SELECT attname FROM pg_attribute WHERE attrelid = 'travel'::regclass;

Here's something a little more useful:

SELECT attname
FROM pg_attribute
WHERE attrelid = 'travel'::regclass
  AND attisdropped IS FALSE
  AND attnum >= 1
ORDER BY attnum;

If you're using PostgreSQL 7.4 or later then you could also use the
Information Schema; see the documentation for details.

SELECT column_name
FROM information_schema.columns
WHERE table_name = 'travel'
ORDER BY ordinal_position;

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-novice by date:

Previous
From: Afton & Ray Still
Date:
Subject: find column names from query
Next
From: "Tjibbe Rijpma"
Date:
Subject: Re: find column names from query