From: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> |
---|---|
To: | Alan Chandler <alan(at)chandlerfamily(dot)org(dot)uk> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Matching the MYSQL "Describe <table-name>" command |
Date: | 2005-04-24 18:31:23 |
Message-ID: | 20050424183123.GD8757@dcc.uchile.cl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Sun, Apr 24, 2005 at 07:02:16PM +0100, Alan Chandler 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.
>
> 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.
select attrelid::regclass, format_type(atttypid, atttypmod) from
pg_attribute
I think it does more or less what you want.
The easiest way to know this sort of info is start psql with -E, and
then describe a table using \d. It will show you what queries it
issued.
attrelid is a FK to pg_class.oid, which is a system (therefore hidden)
column.
--
Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
"Lo esencial es invisible para los ojos" (A. de Saint Exúpery)
From | Date | Subject | |
---|---|---|---|
Next Message | Stephen Frost | 2005-04-24 18:53:25 | Re: Matching the MYSQL "Describe <table-name>" command |
Previous Message | Alan Chandler | 2005-04-24 18:02:16 | Matching the MYSQL "Describe <table-name>" command |