On Fri, Jan 9, 2015 at 2:21 PM, Michael Bayer <mike...@zzzcomputing.com> wrote: > > > Jon Nelson <jnel...@jamponi.net> wrote: > >> >>> so you could use either merge() or merge_result() but to avoid any SQL set >>> load=False. >> >> When I tried with load=False, I got an error. I am using 0.9.8. > > care to be more specific
Absolutely. It took me a bit to grab a bite to eat and whip up a quick test example. I hope the following is more useful! With the following code, I see one query (as expected): SELECT foo.c1 AS foo_c1, foo.c2 AS foo_c2 FROM foo WHERE foo.c1 IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Followed by 10 more queries (unexpected). If I use merge_result the same thing happens. If I use merge_result with load=False, I get the following error: sqlalchemy.exc.InvalidRequestError: merge() with load=False option does not support objects transient (i.e. unpersisted) objects. flush() all changes on mapped instances before merging with load=False. <NOT VERY GOOD CODE> import logging import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Foo(Base): __tablename__ = 'foo' c1 = sa.Column(sa.INTEGER(), primary_key=True, nullable=False) c2 = sa.Column(sa.Unicode(), nullable=False) def test(dbsess_factory): dbsess = dbsess_factory() with dbsess.begin(): keys = list(range(10)) foos = [ Foo(c1=i, c2=u'%d' % (i,)) for i in keys ] dbsess.query(Foo).filter(Foo.c1.in_(keys)).all() [ dbsess.merge(f) for f in foos ] # also tried: # dbsess.query(Foo).merge_result(foos) def main(): engine = sa.create_engine('sqlite:///foo.db') Base.metadata.create_all(engine) dbsess_factory = sa.orm.sessionmaker(bind=engine, autocommit=True, autoflush=False) test(dbsess_factory) if __name__ == '__main__': logging.basicConfig(level=logging.INFO) logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) main() </NOT VERY GOOD CODE> -- Jon Software Blacksmith -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.