From: Steve Midgley <public@misuse.org>
To: pgsql-sql@postgresql.org
Subject: Columns view? (Finding column names for a table)
Date: Wed, 06 Feb 2008 12:33:25 -0800
Message-ID: <20080206203334.8B2B52E01F8@postgresql.org> (raw)
Hi,
I see this documentation item but can't figure out how to use it:
http://www.postgresql.org/docs/8.2/interactive/infoschema-columns.html>The view columns contains information about all table columns (or view
>columns) in the database.
However, if I execute "select columns;" I get a not found error. I'm
sure there's some simple explanation - I'm interested specifically in
listing the column names of a specific table (in Pg 8.2). The manual
SQL I've developed is (where [table_name] is the table I want columns
for):
select pg_attribute.attname, * from pg_attribute
join pg_class on pg_class.oid = pg_attribute.attrelid
where
pg_class.relname = '[table_name]'
and
attnum > 0
and atttypid > 0
Not pretty but seems to work. Of course if there were a view that
encapsulated this and future-proofed it, that'd be much nicer.
Any assistance is appreciated! Thanks,
Steve
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: public@misuse.org
Subject: Re: Columns view? (Finding column names for a table)
In-Reply-To: <20080206203334.8B2B52E01F8@postgresql.org>
* 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