Python DB-API problem with PostgresSQL pgdb.

From: Carwyn Edwards <cedward1(at)inf(dot)ed(dot)ac(dot)uk>
To: pgsql-interfaces(at)postgresql(dot)org
Cc: andre(at)via(dot)ecp(dot)fr, pgsql-admin(at)postgresql(dot)org
Subject: Python DB-API problem with PostgresSQL pgdb.
Date: 2003-01-27 05:06:13
Message-ID: 3E34BE45.6010309@inf.ed.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-interfaces


The Python DB-API (2.0) specifies that on creation a connection object
is to start a transaction if the database supports them. The pgdb
implementation of the DB-API does this:

>>> Begin Listing 1
class pgdbCnx:

def __init__(self, cnx):
self.__cnx = cnx
self.__cache = pgdbTypeCache(cnx)
try:
src = self.__cnx.source()
src.execute("BEGIN")
except:
raise OperationalError, "invalid connection."

>>> End Listing 1

This is all well and good except there does not seem to be any way of
NOT starting a transaction block. This is a real problem if you are
trying to create admin scripts that automate database creation as CREATE
DATABASE in PostgreSQL can not be called from within a transaction
block. Listing 2 shows the raw SQL typed into psql that simulates what
happens from the pgdb module when you try and create a database:

>>> Begin Listing 2
cedward1=# begin;
BEGIN
cedward1=# create database thingy;
ERROR: CREATE DATABASE: may not be called in a transaction block

>>> End Listing 2

I'll let the experts argue as to whether this is a problem for Python's
DB-API or a PostgreSQL issue.

Carwyn

Browse pgsql-admin by date

  From Date Subject
Next Message Jerry Asher 2003-01-27 05:48:33 restricting identd to just the loopback adapter.
Previous Message Tom Lane 2003-01-27 00:42:14 Re: Cannot connect to the database (PG 7.3)

Browse pgsql-interfaces by date

  From Date Subject
Next Message Patrick Welche 2003-01-27 18:19:20 Re: where is the libpq++ ??
Previous Message James H. Cloos Jr. 2003-01-27 03:19:57 Re: where is the libpq++ ??