Hi, Attached is a simple script that inserts a record using Table.insert().execute() method and session.execute(Table.insert()).
When I tried running session.execute(Table.select()), both records inserted by Table.insert().execute() and session.execute(Table.insert()) are retrieved, but when I tried running Table.select().execute(), only the record inserted through Table.insert().execute() is shown. What are the differences between session.execute() and Table.insert/select.execute() ? Are they using different connection objects? Or is this behavior much more related to the transactions used by both execute methods? Note that when using sqllite in memory db, both records inserted by both methods are always retrieved when query is issued. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
from sqlalchemy import create_engine, Column, Integer, String from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base import sqlalchemy.pool as pool import psycopg2 def getconn(): c = psycopg2.connect(user='postgres', host='127.0.0.1', database='session_test') return c engine = create_engine('postgresql+psycopg2://', creator=getconn) Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) def __init__(self, name): self.name = name Base.metadata.create_all(engine) Base.metadata.bind = engine Session = sessionmaker(bind=engine) session = Session() session.execute(User.__table__.insert().values(name='John')) User.__table__.insert().values(name='Tim').execute() # Only user Tim is shown print User.__table__.select().execute().fetchall() # Both user Tim and John are shown print session.execute(User.__table__.select()).fetchall() session.commit()