PyGres????

Eric Jacobs none at none
Mon Aug 7 22:47:55 EDT 2000


In article <slrn8ouf7c.i4p.kc5tja at garnet.armored.net>,
kc5tja at garnet.armored.net (Samuel A. Falvo II) wrote:
> I've managed to get ahold of PyGres, a module that allows Python
> applications to access Postgre databases.  However, there isn't a *word*
> of documentation *anywhere* on how to use this thing, not with it, nor
> on the Internet, based on my Google and python.org searches.

See the file README. It's in a prominent location in the source
distribution.

> I'm having two issues.  First, I can't seem to connect to a database
> without typing the name of the database *precisely*.  That is, it's not
> case insensitive.  For example, basics.DB("testDB") might work, while
> basics.DB("testdb") will likely NOT work.  A minor issue, and one which
> I can work around.  But it really is very annoying.

See the system catalog pg_database. You can query it using the ~*
operator to figure the exact capitalization of the name.

Alternatively, Python has nice string.lower and string.upper functions
(now methods too) that you can wrap around when you create and access
the database.

> Second, and far more important, is how the heck do I access individual
> records piecemeal?  In other words, suppose I have:
> 
> 	>>> import basics	# from /usr/share/doc/python-pygres/tutorial
>       >>> db = basics.DB("testDB")
>       >>> db.query("Select * from weather;");
> 
> the db.query() function call above will return a *string* containing the
> PostgreSQL table information.  This formatting is thoroughly
> unacceptable for my needs.  Is there any way to get that DB object
> return something more suitable for automated processing, such as a list
> of lists:
> 
> 		ColumnA | ColumnB
> 		--------+--------
> 		  45    |   90
> 		 22.5   |   50
>  
> would be returned as:
> 
> 	[[45,22.5],[90,50]]

db.query(...).getresult()

BTW, query does not return a string. PyGres uses a custom print method
to let you easily view the query in interactive mode. (Try it with
a large query -- it will spawn a pager.)

There is also a DB-API interface available. (import pgdb)



More information about the Python-list mailing list