Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 5BC529FB277 for ; Fri, 27 Oct 2006 07:53:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 32806-04 for ; Fri, 27 Oct 2006 07:53:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from nihrelayxway.hub.nih.gov (mailfwd.nih.gov [128.231.90.106]) by postgresql.org (Postfix) with ESMTP id A67989FA6AF for ; Fri, 27 Oct 2006 07:53:33 -0300 (ADT) Received: from pressa.nci.nih.gov ([137.187.209.230]) by nihrelayxway.hub.nih.gov with ESMTP; 27 Oct 2006 06:53:32 -0400 X-IronPortListener: NIH_Relay X-SBRS: None X-IronPort-AV: i="4.09,365,1157342400"; d="scan'208"; a="450691416:sNHT14116596" From: Sean Davis Reply-To: sdavis2@mail.nih.gov Organization: NIH/NCI To: pgsql-interfaces@postgresql.org Subject: Re: How to get table definition of a PostgreSQL table Date: Fri, 27 Oct 2006 06:53:18 -0400 User-Agent: KMail/1.9.1 Cc: Sandeep Khandelwal References: <20061027062556.97956.qmail@web33305.mail.mud.yahoo.com> In-Reply-To: <20061027062556.97956.qmail@web33305.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200610270653.18624.sdavis2@mail.nih.gov> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200610/28 X-Sequence-Number: 6311 On Friday 27 October 2006 02:25, Sandeep Khandelwal wrote: > Hi. > > I would like to get field's name, datatype of each field, length of each > field and precision of each field of a PostgreSQL table. Please let me SQL > query to get this information. See these two chapters in the postgresql docs: http://www.postgresql.org/docs/8.1/interactive/catalogs.html http://www.postgresql.org/docs/8.1/interactive/information-schema.html Each has advantages over the other. Also, if you start psql with the flag --echo-hidden, when you do commands like \dt and \d+, psql will show you the sql it uses to produce that output. Sean