Hi all,

I'd like to use SQLAlchemy to connect to a db server, create a
database, and then start using it. However, it appears that the
SQLAlchemy api assumes the existence of a database to connect to. I'm
able to connect to the server without a database specified:

>>> con = 'postgres://postgres:[EMAIL PROTECTED]'
>>> m = MetaData(bind=con)
>>> m.get_engine()
<sqlalchemy.engine.base.Engine object at 0x00E6B470>

However, when I try to execute a query to create the database, it
fails because CREATE DATABASE "cannot run inside a transaction block":

>>> c = m.get_engine().connect()
>>> c.execute('CREATE DATABASE test_db')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\eng
ine\base.py", line 517, in execute
    return Connection.executors[c](self, object, *multiparams,
**params)
  File "c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\eng
ine\base.py", line 532, in execute_text
    self._execute_raw(context)
  File "c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\eng
ine\base.py", line 581, in _execute_raw
    self._execute(context)
  File "c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\eng
ine\base.py", line 599, in _execute
    raise exceptions.SQLError(context.statement, context.parameters,
e)
sqlalchemy.exceptions.SQLError: (ProgrammingError) CREATE DATABASE
cannot run in
side a transaction block
 'CREATE DATABASE test_db' {}

My apologies if there is an easy solution through the API or if this
question has been answered before. I've have been unable to find
anything yet.

Thanks!
Travis


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to