Обсуждение: pypgsql 'create database' problem
from python using PgSQL.
i get:
" libpq.OperationalError: ERROR: CREATE DATABASE: may not be called
in a transaction block"
in a python script i do :
db = PgSQL.connect(database='template1')
cur=db.cursor()
cur.execute("create database tt2")
cur.close()
del db, cur
how does one not be in a transaction block?
what is the correct way to create a db?
rdacker@pacbell.net (rdack) wrote in message news:<644f6688.0110011048.51982136@posting.google.com>...
> from python using PgSQL.
> i get:
> " libpq.OperationalError: ERROR: CREATE DATABASE: may not be called
> in a transaction block"
>
> in a python script i do :
> db = PgSQL.connect(database='template1')
> cur=db.cursor()
> cur.execute("create database tt2")
> cur.close()
> del db, cur
>
> how does one not be in a transaction block?
> what is the correct way to create a db?
answer is to use libpq module. low level interface has method to
execute queries without wrapping in a transaction:
import libpq
db = libpq.PQconnectdb('dbname=%s' % db_name)
db.query('create database %s' % tbl_name)
On 1 Oct 2001 11:48:31 -0700, rdack <rdacker@pacbell.net> wrote:
>from python using PgSQL.
>i get:
>" libpq.OperationalError: ERROR: CREATE DATABASE: may not be called
>in a transaction block"
>
>in a python script i do :
>db = PgSQL.connect(database='template1')
>cur=db.cursor()
>cur.execute("create database tt2")
>cur.close()
>del db, cur
>
>how does one not be in a transaction block?
>what is the correct way to create a db?
Turn on autocommit. For example:
db = PgSQL.connect(database='template1')
db.autocommit = 1 # You must turn on autocommit before creating any cursor.
cur = db.cursor()
cur.execute("create database tt2")
cur.close()
del db, cur
--
____ | Billy G. Allie | Domain....: Bill.Allie@mug.org
| /| | 7436 Hartwell | MSN.......: B_G_Allie@email.msn.com
|-/-|----- | Dearborn, MI 48126|
|/ |LLIE | (313) 582-1540 |
I'm a bit confused about the current state of error codes in Pg. The docs and the mailing list archives seem to indicate that this is a TODO item, however, at least when using Perl with DBD::Pg, when I call $db->err() or examine $DBI::err I get a number back. For instance, 7 if I try to insert too many columns into a row, and a 1 if the connection fails. What's the scoop, and if error codes really do exist, is there a list of such codes? Thanks, Fran