On Oct 4, 2010, at 5:46 PM, Michael Bayer wrote: > > On Oct 4, 2010, at 8:16 AM, Mark Erbaugh wrote: > >> I have a table described with: >> >> BASE = declarative_base(name=APP_ID) >> >> class Period(BASE): >> >> __tablename__ = 'period' >> >> realperiod = Column(Integer, primary_key=True) >> cycle = Column(Integer) >> [more columns] >> >> I want to delete all records with a given value for the "cycle" column. >> With the SQLAlchemy session in the variable session and the desired cycle in >> y, I execute >> >> q = session.query(Period).filter(Period.cycle==y).delete() >> >> This correctly deletes the desired rows and returns the number of rows >> deleted; however, if I turn echo on I see the following SQL commands: >> >> SELECT period.realperiod AS period_realperiod >> FROM period >> WHERE period.cycle = ? >> >> DELETE FROM period WHERE period.cycle = ? >> >> If I were doing this in SQL, I would to the first command as >> >> SELECT count(*) >> FROM period >> WHERE period.cycle = ? >> >> to get the count of rows to be deleted so I am wondering if I am doing >> things correctly. > > Most relational databases report the number of rows matched by any UPDATE or > DELETE statement that just executed, and SQLA acquires this value via > cursor.rowcount on any such statement, so a separate count() call is not > required. > > 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.
Thanks. What is the purpose of >> SELECT period.realperiod AS period_realperiod >> FROM period >> WHERE period.cycle = ? that appears to be generated by the session.query ... call? Mark -- 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.