views:

68

answers:

1

So I have some results which I've got from the install table, like so:

install = metadata.tables['install']  
results = session.query(install) #<sqlalchemy.orm.query.Query object>

I'd like to insert these same results into the install_archive table.

I'm not entirely sure how to do this, because I don't want to duplicate the schema by defining an install-archive object and then parsing the results into that. I believe I'm not using the ORM, because I'm just reflecting (is that the right term?) the tables and querying them.

All the tutorials I can see use the ORM.

A slow way of doing it, in psudocode, would be:

for id in result.all():
    install_archive.insert(install(id))

Thanks in advance!

A: 

You can do something like this (changing the SELECT to suit your needs). Just make sure the two tables have the same structure.

INSERT INTO `table1` (SELECT * FROM `table2`);
Michael Mior