python Programming Glossary: insertfromselect
How do I INSERT INTO t1 (SELECT * FROM t2) in SQLAlchemy? http://stackoverflow.com/questions/1849375/how-do-i-insert-into-t1-select-from-t2-in-sqlalchemy import Executable ClauseElement class InsertFromSelect Executable ClauseElement def __init__ self table select self.table.. self.table table self.select select @compiler.compiles InsertFromSelect def visit_insert_from_select element compiler kw return INSERT.. asfrom True compiler.process element.select insert InsertFromSelect t1 select t1 .where t1.c.x 5 print insert Produces INSERT INTO..
creating a temporary table from a query using sqlalchemy orm http://stackoverflow.com/questions/9593610/creating-a-temporary-table-from-a-query-using-sqlalchemy-orm example below . For copying the data I then would use the InsertFromSelect example . Here is a working example from sqlalchemy import Table.. from sqlalchemy.sql.expression import UpdateBase class InsertFromSelect UpdateBase def __init__ self table select self.table table self.select.. table select self.table table self.select select @compiles InsertFromSelect def visit_insert_from_select element compiler kw return INSERT..
|