Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8285A47636F; Mon, 27 Jan 2003 00:06:14 -0500 (EST) Received: from monolith.carwyn.com (pc-80-195-55-88-ed.blueyonder.co.uk [80.195.55.88]) by postgresql.org (Postfix) with ESMTP id 39F2547622E; Mon, 27 Jan 2003 00:06:13 -0500 (EST) Received: from inf.ed.ac.uk (monolith.carwyn.com [127.0.0.1]) by monolith.carwyn.com (8.12.5/8.12.5) with ESMTP id h0R56D17018922; Mon, 27 Jan 2003 05:06:17 GMT Message-ID: <3E34BE45.6010309@inf.ed.ac.uk> Date: Mon, 27 Jan 2003 05:06:13 +0000 From: Carwyn Edwards Reply-To: cedward1@inf.ed.ac.uk Organization: University of Edinburgh User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3a) Gecko/20021212 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-interfaces@postgresql.org Cc: andre@via.ecp.fr, pgsql-admin@postgresql.org Subject: Python DB-API problem with PostgresSQL pgdb. Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/297 X-Sequence-Number: 7139 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