From: George Young <gry@ll.mit.edu>
To: pgsql-sql@postgresql.org
Subject: Re: viewing the description of tables from python DB-API
Date: Mon, 7 Aug 2006 15:20:31 -0400
Message-ID: <20060807152031.e3e1ef59.gry@ll.mit.edu> (raw)
In-Reply-To: <20060801223740.4B60E9FB1D4@postgresql.org>
References: <20060801223740.4B60E9FB1D4@postgresql.org>
On Tue, 1 Aug 2006 15:30:48 -0700
"Daniel Joo" <djoo@vistagen-inc.com> 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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gry@ll.mit.edu
Subject: Re: viewing the description of tables from python DB-API
In-Reply-To: <20060807152031.e3e1ef59.gry@ll.mit.edu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox