my_new_posts = {(1): post1, (5): post5, (1000): post1000}
for each in posts.query.filter(posts.id.in_(list(my_new_posts.keys()))).all():
    pass
SQLAlchemy - performing a bulk upsert (if exists, update, else insert) in postgresql