Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Anyone know a good Pygresql Tutorial for Interfacing betweenPython &Postgresql

Reply
Thread Tools

Anyone know a good Pygresql Tutorial for Interfacing betweenPython &Postgresql

 
 
Chuck Amadi
Guest
Posts: n/a
 
      06-16-2004
Hi all

Anyone know a good Pygresql Tutorial for Interfacing between Python &
Postgresql .

Cheers

Chuck


 
Reply With Quote
 
 
 
 
Peter Maas
Guest
Posts: n/a
 
      06-16-2004
Chuck Amadi schrieb:
> Anyone know a good Pygresql Tutorial for Interfacing between Python &
> Postgresql .


Tried Google and found

http://www.pygresql.org/README.txt


Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail http://www.velocityreviews.com/forums/(E-Mail Removed)
-------------------------------------------------------------------
 
Reply With Quote
 
 
 
 
John fabiani
Guest
Posts: n/a
 
      06-16-2004
Peter Maas wrote:
> Chuck Amadi schrieb:
>
>> Anyone know a good Pygresql Tutorial for Interfacing between Python &
>> Postgresql .

>
>
> Tried Google and found
>
> http://www.pygresql.org/README.txt
>
>
> Mit freundlichen Gruessen,
>
> Peter Maas
>

I'm a newbie so take what I have to say with a grain of salt. The
problem for me was not how to make a connection to postgres but how to
use the data returned. Maybe I'm missing something but almost every
sample I could find did not work as expected. The first issue was each
example (ones found via google and in O'Reilly books) show that a tuple
is returned. At least for my postgres driver (module) the return type
is a list. The next issue is how to loop through the data. Also the
examples use fetchone() as an example. But even they did not work
because of the 'tuple' issue and most of the time I needed
fetchmany(100) or fetchall(). I still have not resolved most of the
issues but I'm still learning.
John
 
Reply With Quote
 
Peter Maas
Guest
Posts: n/a
 
      06-17-2004
John fabiani schrieb:
> I'm a newbie so take what I have to say with a grain of salt. The
> problem for me was not how to make a connection to postgres but how to
> use the data returned.


Here is a tested example code. It relies on pyPgSQL but PyGreSQL
should be quite similar especially the data access:

-----------------------------------------------------------------
#!/usr/bin/env python
# -*- coding: latin-1 -*-

"""
Example code how to read data from a PostgreSQL database. You
need the pyPgSQL module which is DB-API 2.0 compliant so that
the calls are not database dependent except of connection URL
and some SQL capabilities.
"""

# PostgreSQL interface module
from pyPgSQL import PgSQL

if __name__ == '__main__':
# open connection
con = PgSQL.connect(None, "aUser", "aPasswd", "aHost", "aDatabase")

# create cursor
c_adr = con.cursor()

# let cursor execute an SQL command
c_adr.execute("SELECT * FROM address")

# fetch a result set
r_adr = c_adr.fetchmany(10)

# The result set is a list of records.
print r_adr[0]

# Each record is a dictionary like object with field names as keys.
print r_adr[0].keys()

# The field values are the dictionary values.
print r_adr[0]["firstname"]

# print all records
for record in r_adr:
print record
-----------------------------------------------------------------


Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail (E-Mail Removed)
-------------------------------------------------------------------
 
Reply With Quote
 
=?ISO-8859-1?Q?Gerhard_H=E4ring?=
Guest
Posts: n/a
 
      06-19-2004
Peter Maas wrote:
> Chuck Amadi schrieb:
>
>> Anyone know a good Pygresql Tutorial for Interfacing between Python &
>> Postgresql .

>
>
> Tried Google and found
>
> http://www.pygresql.org/README.txt


This describes the PyGreSQL proprietory interface. It would IMO be a
much better idea to use a DB-API compliant interface, like pyPgSQL or
psycopg offer. Or PyGreSQL through the pgdb module included.

-- Gerhard

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ann: Python-SIMPL online tutorial updated to include examples ofcloud interfacing bobicanprogram Python 0 12-15-2011 09:17 PM
Q. Anyone know of a good typing tutorial? George Computer Support 9 11-12-2004 05:38 AM
Do you know any good Cool Edit Pro tutorial link Gee Computer Support 0 08-30-2004 10:25 PM
I know, I know, I don't know Andries Perl Misc 3 04-23-2004 02:17 AM
Re: Anyone know of a good tutorial site for datalist datagrid? Mr Gordonz ASP .Net 1 08-10-2003 02:07 AM



Advertisments