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!
install_archive \
.insert() \
.from_select(names=['col1', 'col2'], # array of column names that your query returns
select=session.query(install)) # your query or other select() object
This results in (PostgreSQL dialect)
INSERT INTO install_archive (col1, col2)
SELECT install.col1, install.col2
FROM install;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With