8

I'd like to create a temporary table in SQLAlchemy. I can build a CREATE TABLE statement with a TEMPORARY clause by calling table._prefixes.append('TEMPORARY') against a Table object, but that's less elegant than table.select().prefix_with() used to add a prefix to data manipulation language expressions.

Is there an equivalent to .prefix_with() for DDL?

joeforker
  • 38,323
  • 36
  • 144
  • 239

1 Answers1

11

No, prefix_with() is defined for SELECT and INSERT only. But convenient way to add prefix to CREATE TABLE statement is passing it into table definition:

t = Table(
    't', metadata,
    Column('id', Integer, primary_key=True),
    # ...
    prefixes=['TEMPORARY'],
)
Denis Otkidach
  • 30,474
  • 8
  • 74
  • 96
  • 1
    I was trying to make a temporary table that looked like a reflected table. It wound up being more trouble than it was worth, trying to derive new Table objects from existing ones instead of making a function that returns several similar Table objects. – joeforker Dec 05 '09 at 01:32
  • What Engine does this work with? I cannot get "CREATE TEMPORARY TABLE" to work with MSSQL – Chris2048 Sep 05 '18 at 09:20