Re: Matching the MYSQL "Describe " command - Mailing list pgsql-sql

From Stephen Frost
Subject Re: Matching the MYSQL "Describe " command
Date
Msg-id 20050424185324.GD27470@ns.snowman.net
Whole thread Raw
In response to Matching the MYSQL "Describe " command  (Alan Chandler <alan@chandlerfamily.org.uk>)
Responses Re: Matching the MYSQL "Describe " command
List pgsql-sql
* Alan Chandler (alan@chandlerfamily.org.uk) wrote:
> I am rather new to Postgres (running 7.4) but I am trying to port some PHP
> code that has been built to run with mysql.
>
> I have got stuck trying to find the equivalent of the Mysql "DESCRIBE
> <tablename>;" SQL statement that lists the columns and type identifiers of a
> table.

You might want to take a look at the schema called 'information_schema'
and see if you can find what you want there.  The only problem I have
with that, currently anyway, is that it seems to only show things the
current user owns as opposted to what the current user has access to,
which seems a bit silly to me.

> I think I am going to do a SELECT on the "pg_attribute" table, but I don't
> understand what the "attrelid" column of that table refers to.  I need to get
> the table name of the column so that I can restrict the select with a WHERE
> clause so I assumed it was a key into the pg_class table, but I can't see a
> column in this table that could potentially correspond and therefore I could
> join to it.

In psql you can do: \set ECHO_HIDDEN 'yes'
Then just run whatever psql \d or other command you want and it'll give
you the queiries it used.  Using information_schema should technically
be more portable though, I believe.
Stephen

pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Matching the MYSQL "Describe " command
Next
From: Theodore Petrosky
Date:
Subject: to_char(interval) ?