X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E832F9FB36A for ; Mon, 7 Aug 2006 16:40:24 -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 46487-08-2 for ; Mon, 7 Aug 2006 16:40:14 -0300 (ADT) X-Greylist: delayed 00:18:29.554614 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 434029FB22F for ; Mon, 7 Aug 2006 16:39:50 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from ll.mit.edu (LLMAIL.LL.MIT.EDU [129.55.12.40]) by svr4.postgresql.org (Postfix) with ESMTP id 7AD545AFB3E for ; Mon, 7 Aug 2006 19:21:18 +0000 (GMT) Received: (from smtp@localhost) by ll.mit.edu (8.12.10/8.8.8) id k77JKwBn006624 for ; Mon, 7 Aug 2006 15:20:58 -0400 (EDT) Received: from UNKNOWN( ), claiming to be "sty.llan" via SMTP by llmail, id smtpdAAA.AaGml; Mon Aug 7 15:20:32 2006 Date: Mon, 7 Aug 2006 15:20:31 -0400 From: George Young To: pgsql-sql@postgresql.org Subject: Re: viewing the description of tables from python DB-API Message-Id: <20060807152031.e3e1ef59.gry@ll.mit.edu> In-Reply-To: <20060801223740.4B60E9FB1D4@postgresql.org> References: <20060801223740.4B60E9FB1D4@postgresql.org> Organization: MIT Lincoln Laboratory X-Mailer: Sylpheed version 2.2.4 (GTK+ 2.8.0; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200608/43 X-Sequence-Number: 26001 On Tue, 1 Aug 2006 15:30:48 -0700 "Daniel Joo" wrote: > Is there a way to view the list of all tables from python (or any other > languages for that matter) DB-API? What I'm looking for is a command > similar to the meta-command '\d' that works with the psql client. The cursor object has a "description" data member. Look at the DB-API spec: http://www.python.org/dev/peps/pep-0249/ under "Cursor Objects". Python 2.3.3 (#1, Jan 3 2004, 07:17:11) [GCC 3.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pgdb >>> db=pgdb.connect(database='pigrestore', host='ivy') >>> cur=db.cursor() >>> cur.execute('select * from machine') >>> print cur.description [('machine_name', 'text', -1, -1, None, None, None), ('machine_id', 'int2', -1, 2, None, None, None), ('area', 'text', -1, -1, None, None, None), ('text', 'text', -1, -1, None, None, None)] >>> -- "Are the gods not just?" "Oh no, child. What would become of us if they were?" (C.S. Lewis)