That works, thanks. Currently, I'm using __declare_last__() to modify 
__table__.schema (SQLite) or __table__._prefixes (Oracle, PostgreSQL), once the 
dialect is known. For the latter two I'm also monkey-patching 
post_create_table(), which seemed easier to do than to completely re-implement 
table creation, even if it does not look that nice.

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Michael Bayer
> Sent: 22 November 2013 16:17
> To: [email protected]
> Subject: Re: [sqlalchemy] SQLite temporary tables
> 
> 
> On Nov 22, 2013, at 6:24 AM, Gombas, Gabor
> <[email protected]> wrote:
> 
> > Hi,
> >
> > How should one create SQLite temporary tables using SQLAlchemy? The
> following does not work:
> >
> >     from sqlalchemy import create_engine, Column, String
> >     from sqlalchemy.ext.declarative import declarative_base
> >     from sqlalchemy.orm import sessionmaker
> >     from sqlalchemy.schema import CreateTable
> >
> >     Base = declarative_base()
> >
> >     class TempTest(Base):
> >         __tablename__ = 'temp_test'
> >         __table_args__ = {'schema': 'temp'}
> >         name = Column(String, primary_key=True)
> >
> >     engine = create_engine('sqlite:////tmp/testdb', echo=True)
> >     Session = sessionmaker(bind=engine)
> >     session = Session()
> >
> >
>       TempTest.__table__.create(session.bind.execution_options(autoco
> mmit=False))
> >     session.add(TempTest(name='foo'))
> >     session.flush() # Fails
> >
> > Although I see the "CREATE TABLE" being emitted, INSERT fails saying the
> table does not exist. If instead of calling TempTest.__table__.create() I use
> the underlying DBAPI connection, then I can make it work, but it's ugly:
> 
> you use create() but use the session's current transaction-bound connection:
> 
> TempTest.__table__.create(session.connection())
> 
> I'm assuming you're using @compiles somewhere to get the "TEMPORARY"
> syntax in there.
> 



--------------------------------------------------------------------------------

NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or 
views contained herein are not intended to be, and do not constitute, advice 
within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and 
Consumer Protection Act. If you have received this communication in error, 
please destroy all electronic and paper copies and notify the sender 
immediately. Mistransmission is not intended to waive confidentiality or 
privilege. Morgan Stanley reserves the right, to the extent permitted under 
applicable law, to monitor electronic communications. This message is subject 
to terms available at the following link: 
http://www.morganstanley.com/disclaimers. If you cannot access these links, 
please notify us by reply message and we will send the contents to you. By 
messaging with Morgan Stanley you consent to the foregoing.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to