Re: newbie question... how do I get table structure? - Mailing list pgsql-general

From Tom Lane
Subject Re: newbie question... how do I get table structure?
Date
Msg-id 555.1076084123@sss.pgh.pa.us
Whole thread Raw
In response to Re: newbie question... how do I get table structure?  (Franco Bruno Borghesi <franco@akyasociados.com.ar>)
Responses Re: newbie question... how do I get table structure?  (Franco Bruno Borghesi <franco@akyasociados.com.ar>)
List pgsql-general
Franco Bruno Borghesi <franco@akyasociados.com.ar> writes:
> Does anyone know if the ansi sql standard defines any way to do this?
> I've seen the DESCRIBE TABLE/INDEX/... or SHOW TABLE/INDEX/... commands
> in other databases, but I don't really know if they are extensions or
> not.

They are extensions (and very nonstandard ones at that).  What the SQL
standard provides are standardized views of the system catalogs located
in the INFORMATION_SCHEMA schema.  The per-spec way to do this would
be something like

select column_name, data_type
from information_schema.columns
where table_name = 'foo'
order by ordinal_position;

Now Postgres only got around to supporting the INFORMATION_SCHEMA views
in 7.4 (although in principle you could have defined most of these views
earlier, certainly in 7.3).  I'm not real sure how many other DBs
support INFORMATION_SCHEMA either ... it may not be all that "standard".

            regards, tom lane

pgsql-general by date:

Previous
From: Anton Nikiforov
Date:
Subject: PL/Ruby
Next
From: Pavel Stehule
Date:
Subject: Re: how can I select into an array?