dbTalk Databases Forums  

Re: PyPgSQL help

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: PyPgSQL help in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Oliver Fromme
 
Posts: n/a

Default Re: PyPgSQL help - 07-26-2004 , 04:52 AM







Bob Jarman wrote:
Quote:
Off-topic re Python. I'm trying to connect to Postgres 7.4.2 using
python.
I'm using PyGreSQL: http://www.druid.net/pygresql/
You simply "import pgdb" and get a Python DB-API 2.0-
compliant interface. Here's a short excerpt from one
of my Python programs (simplified for brevity):

import sys
import pgdb

try:
db = pgdb.connect(host = "foo.bar", database = "baz",
user = "chuck", password = "xxxxxxxx")
except pgdb.Error, detail:
print "Cannot open connection to database!"
print detail
sys.exit (1)

try:
cursor = db.cursor()
except pgdb.Error, detail:
print "Cannot acquire cursor for database!"
print detail
sys.exit (1)

try:
cursor.execute ("SELECT * FROM moonlight")
result = cursor.fetchall()
except pgdb.DatabaseError, detail:
print "SQL query failed!"
print detail
sys.exit (1)

db.close()

The full Python DB-API 2.0 documentation can be found in
PEP 249: http://www.python.org/peps/pep-0249.html

Best regards
Oliver

--
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

Python is executable pseudocode. Perl is executable line noise.

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.