0

I would to execute a sql request (a SELECT one) by a mysql database. The rows coming from this request would then be used to populate rows in another table. All by using the sqlalchemy ORM. I believe it could look like a sql merge into statement, which would take care of the updates of rows previously added in the second table.

Typically my sqlalchemy query looks like this:

print sess.query(User.platform, User.population_current,            
    func.count(distinct(User._id))).filter(func.date(User.updated_at) == date.today()).all()

And I would like to use the results of this request to populate another table.

jgrec
  • 97
  • 9
  • 1
    Possible duplicate of [SQLAlchemy: Inserting the results of a query into another table](http://stackoverflow.com/questions/3070733/sqlalchemy-inserting-the-results-of-a-query-into-another-table) – themanatuf Feb 21 '17 at 13:38
  • @themanatuf some answers are indeed in the thread you mentionned, but what I don't understand in it is how to perform upserts – jgrec Feb 21 '17 at 13:43
  • Bulk upserts are a pain. zzzeek has a possible solution here: https://bitbucket.org/zzzeek/sqlalchemy/issues/960/implement-merge-and-or-pg-on-conflict-and – reptilicus Feb 21 '17 at 16:35
  • Also http://stackoverflow.com/questions/25694234/bulk-update-in-sqlalchemy-core-using-where – reptilicus Feb 21 '17 at 16:39

0 Answers0