Setting an "autocommit" setting on a single raw_connection() won't work also because that's just one connection out of several in the pool. The operation should be performed on a Connection:
c = engine.connect() c.detach() # so it is never returned to the pool, since we're changing settings c.connection.set_isolation_level(...) c.execute(<statement>) Will add this in 0.7 to psycopg2's allowed list of isolation modes: c.execution_options(isolation_level='AUTOCOMMIT') - ticket #2072 On Feb 22, 2011, at 9:18 PM, Eric Ongerth wrote: > Even with that "autocommit" transaction isolation level, you probably > need to commit the "create database" before you try to add tables to > it. > > On Feb 22, 1:45 pm, Toninho Nunes <toninhonu...@gmail.com> wrote: >> Hi see my source code below >> >> import sqlalchemy >> import psycopg2 >> from sqlalchemy import create_engine, Table, MetaData, Integer, >> String, ForeignKey, Column, LargeBinary >> from sqlalchemy.sql import text >> >> db_engine = create_engine('postgresql+psycopg2:// >> postgres:password@localhost/newscom3', echo=True) >> db_engine.raw_connection().set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) >> db_engine.text("CREATE DATABASE newscom3 WITH OWNER = postgres >> ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'pt_BR.utf8' >> LC_CTYPE = 'pt_BR.utf8' CONNECTION LIMIT = -1;").execute() >> >> metadata = MetaData() >> metadata.create_all(db_engine) >> >> I run the source code, but I receive the following error. >> >> Traceback (most recent call last): >> File "newscomddl.py", line 18, in <module> >> >> db_engine.raw_connection().set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/engine/base.py", line 1874, in raw_connection >> return self.pool.unique_connection() >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/pool.py", line 142, in unique_connection >> return _ConnectionFairy(self).checkout() >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/pool.py", line 369, in __init__ >> rec = self._connection_record = pool.get() >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/pool.py", line 213, in get >> return self.do_get() >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/pool.py", line 732, in do_get >> con = self.create_connection() >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/pool.py", line 147, in create_connection >> return _ConnectionRecord(self) >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/pool.py", line 253, in __init__ >> self.connection = self.__connect() >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/pool.py", line 319, in __connect >> connection = self.__pool._creator() >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/engine/strategies.py", line 82, in connect >> return dialect.connect(*cargs, **cparams) >> File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6- >> py2.6.egg/sqlalchemy/engine/default.py", line 249, in connect >> return self.dbapi.connect(*cargs, **cparams) >> sqlalchemy.exc.OperationalError: (OperationalError) FATAL: database >> "newscom3" does not exist >> None None >> >> I don't get know where are wrong, could you help me? >> >> Thanks, >> >> Toninho Nunes > > -- > 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 > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.