class InsertFromSelect(object): """Form the base for `INSERT INTO table (SELECT ... )` statement.""" # NOTE(tdurakov): Insert from select implementation added to SQLAlchemy # starting from version 0.8.7. Default SQLAlchemy implementation should be # used instead of this. Deprecated. def __new__(cls, table, select, cols=None): if not cols: cols = [c.name for c in table.c] return table.insert(inline=True).from_select(cols, select) def __init__(self, table, select, cols=None): """Form the base for `INSERT INTO table (SELECT ... )` statement. :param table: table to insert records :param select: select query :param cols: list of columns to specify in insert clause :return: Usage example: select = sql.select(table_from) insert = InsertFromSelect(table_to, select, ['id', 'name', 'insert_date']) engine.execute(insert) """