for each in posts.query.filter(posts.id.in_(list(my_new_posts.keys()))).all():
    db.session.merge(my_new_posts.pop(each.id))
SQLAlchemy - performing a bulk upsert (if exists, update, else insert) in postgresql