Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I CREATE TEMPORARY TABLE in SQLAlchemy without appending to Table._prefixes?

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?

like image 381
joeforker Avatar asked Dec 03 '09 21:12

joeforker


People also ask

Which is the correct syntax for creating a temporary table?

To create a Global Temporary Table, add the “##” symbol before the table name. Global Temporary Tables are visible to all connections and Dropped when the last connection referencing the table is closed. Global Table Name must have an Unique Table Name.

Does WITH clause create temporary table?

The WITH clause is an optional clause used to contain one or more common table expressions (CTE) where each CTE defines a temporary table that exists for the duration of the query. Each subquery in the WITH clause specifies a table name, an optional list of column names, and a SELECT statement.

Why do we create temporary tables?

The main purpose of the temporary tables is to store data temporarily. On the other hand, in-memory optimized tables have been entered our data life with SQL Server 2014, and schema only optimized tables can store the data until the database restart.


1 Answers

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'],
)
like image 82
Denis Otkidach Avatar answered Sep 22 '22 23:09

Denis Otkidach