pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Carwyn Edwards <cedward1@inf.ed.ac.uk>
To: pgsql-interfaces@postgresql.org
Cc: andre@via.ecp.fr
Cc: pgsql-admin@postgresql.org
Subject: Python DB-API  problem with PostgresSQL pgdb.
Date: Mon, 27 Jan 2003 05:06:13 +0000
Message-ID: <3E34BE45.6010309@inf.ed.ac.uk> (raw)


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




view thread (2+ messages)  latest in thread

Message-ID: <3E34BE45.6010309@inf.ed.ac.uk>
Permalink:  ../3E34BE45.6010309@inf.ed.ac.uk/
Also on:    postgresql.org/message-id/3E34BE45.6010309@inf.ed.ac.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: cedward1@inf.ed.ac.uk, andre@via.ecp.fr, pgsql-admin@postgresql.org
  Subject: Re: Python DB-API  problem with PostgresSQL pgdb.
  In-Reply-To: <3E34BE45.6010309@inf.ed.ac.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox