Re: PyPgSQL help

From: Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de>
To: rjarman(at)knology(dot)net (Bob Jarman)
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: PyPgSQL help
Date: 2004-07-26 09:52:23
Message-ID: 200407260952.i6Q9qNY6030221@lurza.secnetix.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


Bob Jarman wrote:
> 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.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Chris 2004-07-26 12:16:18 hexdecimal constant in postgresql
Previous Message Oliver Fromme 2004-07-26 09:16:57 Re: Load Balancing / Failover cluster