473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Anyone know a good Pygresql Tutorial for Interfacing betweenPython &Postgresql

Hi all

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

Cheers

Chuck
Jul 18 '05 #1
4 5796
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 pe********@mplusr.de
-------------------------------------------------------------------
Jul 18 '05 #2
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
Jul 18 '05 #3
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 pe********@mplusr.de
-------------------------------------------------------------------
Jul 18 '05 #4
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

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alexander Ross | last post by:
Lets say I want to execute 3 postgresql queries in a row based on the inputs in a php form...Here's the catch though. What happens if #1 and #2 execute perfectly, but #3 fails for one reason or...
9
by: W. Borgert | last post by:
Hi, I'm not new to Python, but new to databases and PostgreSQL. I like to write a PostgreSQL client application (not code running inside of the RDBMS), and Debian has four modules: ...
2
by: Ian S. Nelson | last post by:
What's the current state of Python and PostgreSQL? There is PoPy, PygreSQL and PsycoPG, maybe others? PygreSQL was part of the PostgreSQL tree, now it's not. What's up with it? Then a Zope...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
2
by: Josué Maldonado | last post by:
Hello list, Does anyone know about or use a good postgresql reporting tool. I appreciate any help or comment about it. -- Josué Maldonado
14
by: Manuel Tejada | last post by:
Hi My box: RedHat 9.0, Pentium III Recently I upgraded from PostgreSQL 7.3.2 to PostgreSQL 7.4.1. The PostgreSQL 7.3.2's rpms were installed from RehHat CDs The PostgreSQL 7.4.1's rpms I used...
2
by: Mike Morris | last post by:
Hi, I've setup a postgres server (7.4) and confirmed that SSL is enabled - I can successfully connect via tcp socket over SSL using the psql client. From PHP4, how can I get the pg_connect...
8
by: dananrg | last post by:
Seems like most web hosting providers support MySQL, but not PostgreSQL. I need a web hosting account that supports PostgreSQL for a particular personal project I'm working on (as well as Python,...
3
by: dpholmes | last post by:
hi everyone, i'm very new to python and to this forum. i'm actually just trying to work through the tutorial on webpy.org. so far, so good, but as i tried to incorporate a postgresql database...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.