X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E8FC953B30 for ; Sun, 24 Apr 2005 15:31:42 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41934-03 for ; Sun, 24 Apr 2005 18:31:34 +0000 (GMT) Received: from sunsite.dcc.uchile.cl (sunsite.dcc.uchile.cl [192.80.24.2]) by svr1.postgresql.org (Postfix) with ESMTP id C338653B19 for ; Sun, 24 Apr 2005 15:31:30 -0300 (ADT) Received: from anakena.dcc.uchile.cl (anakena [192.80.24.6]) by sunsite.dcc.uchile.cl (8.12.11/8.12.11) with ESMTP id j3OIVNir006667; Sun, 24 Apr 2005 14:31:23 -0400 (CLT) Received: by anakena.dcc.uchile.cl (Postfix, from userid 4151) id CCEAD53314; Sun, 24 Apr 2005 14:31:23 -0400 (CLT) Date: Sun, 24 Apr 2005 14:31:23 -0400 From: Alvaro Herrera To: Alan Chandler Cc: pgsql-sql@postgresql.org Subject: Re: Matching the MYSQL "Describe " command Message-ID: <20050424183123.GD8757@dcc.uchile.cl> References: <200504241902.16770.alan@chandlerfamily.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <200504241902.16770.alan@chandlerfamily.org.uk> User-Agent: Mutt/1.5.8i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.34 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE X-Spam-Level: X-Archive-Number: 200504/366 X-Sequence-Number: 21259 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 > ;" 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 () "Lo esencial es invisible para los ojos" (A. de Saint Exúpery)