From: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> |
---|---|
To: | "Scot L(dot) Harris" <webid(at)cfl(dot)rr(dot)com>, Andrew McMillan <andrew(at)catalyst(dot)net(dot)nz> |
Cc: | pgsql-php(at)postgresql(dot)org |
Subject: | Re: table column information |
Date: | 2004-05-18 21:53:35 |
Message-ID: | 200405181753.35869.xzilla@users.sourceforge.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
On Monday 17 May 2004 17:31, Scot L. Harris wrote:
> On Mon, 2004-05-17 at 06:26, Andrew McMillan wrote:
> > On Sun, 2004-05-16 at 23:16 -0400, Scot L. Harris wrote:
> > > > You can also select the column names from the database metadata
> > > > directly:
> > > >
> > > > SELECT attname
> > > > FROM pg_class c join pg_attribute a on c.oid = a.attrelid
> > > > WHERE c.relname = '<your table name>'
> > > > AND a.attnum >= 0;
> > > >
> > > > This approach won't get killed by the efficiency problems above.
> > > >
> > > > Cheers,
> > > > Andrew.
> >
> > When I want to figure out something like this I tend to use "psql -E" so
> > that all queries are echoed before being sent to the backend. Then I do
> > something like "\d <table>" and see what SQL psql generates internally.
> >
> > Also, dig here for detailed information on the postgresql data
> > dictionary tables:
> >
> > http://www.postgresql.org/docs/7.4/interactive/catalogs.html
> >
> > the most useful ones are pg_class and pg_attribute usually (for obvious
> > reasons :-). With 7.4 I also find myself looking at the
> > pg_stat_activity view from time to time as well.
> >
> > Cheers,
> > Andrew.
>
> Thanks to everyone that responded to my question. I have my application
> working as I wanted. I really appreciate all the help that was
> provided.
A little late to the party, but it seems worth mentioning that this
information is also available in the information_schema, which has the
benefits of being sql complient, stable across releases, and keeps you out of
the system catalogs. for example:
cms74=# select column_name from information_schema.columns where table_name =
'current_downloads';
column_name
-------------
start_time
entity_id
(2 rows)
for more on information schema check out
http://www.postgresql.org/docs/7.4/interactive/information-schema.html
Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
From | Date | Subject | |
---|---|---|---|
Next Message | Scot L. Harris | 2004-05-18 22:02:12 | Re: table column information |
Previous Message | Scot L. Harris | 2004-05-17 21:31:44 | Re: table column information |