Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A19042E3265 for ; Mon, 17 Dec 2007 13:35:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 12870-07 for ; Mon, 17 Dec 2007 13:34:54 -0400 (AST) Received: from smtpauth.rollernet.us (smtpauth.rollernet.us [208.11.75.5]) by postgresql.org (Postfix) with ESMTP id B6DC02E35C4 for ; Mon, 17 Dec 2007 13:35:04 -0400 (AST) Received: from smtpauth.rollernet.us (localhost.localdomain [127.0.0.1]) by smtpauth.rollernet.us (Postfix) with ESMTP id 8CFC9594019; Mon, 17 Dec 2007 09:35:02 -0800 (PST) Received: from iron.denterprises.org (ool-4350518c.dyn.optonline.net [67.80.81.140]) by smtpauth.rollernet.us (Postfix) with ESMTP; Mon, 17 Dec 2007 09:35:02 -0800 (PST) Received: from [127.0.0.1] (kell.iron.denterprises.org [192.168.171.80]) by iron.denterprises.org (Postfix) with ESMTP id 0F84D16767E; Mon, 17 Dec 2007 12:35:01 -0500 (EST) Message-ID: <4766B323.6030102@denterprises.org> Date: Mon, 17 Dec 2007 12:34:27 -0500 From: Colin Wetherbee User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: danap@dandymadeproductions.com CC: pgsql-sql@postgresql.org Subject: Re: Describe Table References: <20071217165211.E18222E3202@postgresql.org> In-Reply-To: <20071217165211.E18222E3202@postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 071217-0, 12/17/2007), Outbound message X-Antivirus-Status: Clean X-Rollernet-Abuse: Processed by Roller Network Mail Services. Contact abuse@rollernet.us to report violations. Abuse policy: http://rollernet.us/abuse.php X-Rollernet-Submit: Submit ID 1851.4766b346.56559.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/93 X-Sequence-Number: 29785 danap@dandymadeproductions.com wrote: > I've reviewed much of the documentation and the forums, > but unable to seem to find a easy way to obtain the same > thing as the 'psql \d table' through sql. I know I can create > through collecting info on table, but seems there must be an > easier way. I desire to create a standard type SQL dump > syntax. Briefly, you use the special pg_ tables [0]. The following query is probably not the most efficient way of doing it, but it shows the column names for the "wines" table. The first seven listed are system columns (tableoid - ctid), and the rest are data columns (name - score). You can look at the descriptions for each of the pg_ tables to refine your query a bit, exclude system columns, figure out data types, and so forth. cww=# SELECT pg_class.relname, attname FROM pg_attribute, pg_class WHERE attrelid = pg_class.reltype::integer - 1 AND pg_class.relname = 'wines'; relname | attname ---------+----------------- wines | tableoid wines | cmax wines | xmax wines | cmin wines | xmin wines | oid wines | ctid wines | name wines | vintage wines | origin wines | specific_origin wines | color wines | type wines | description wines | vintner wines | entry_date wines | score (17 rows) This query works on 8.1.9. Colin [0] http://www.postgresql.org/files/documentation/books/aw_pgsql/node183.html