thanks a lot! helpful. On Aug 1, 5:51 am, "King Simon-NFHD78" <simon.k...@motorolasolutions.com> wrote: > vitsin wrote: > > hi, > > can't figure out why raw SQL works fine, but update() is not working: > > 1.working raw SQL: > > self.session.execute("update public.my_table set > > status='L',updated_at=now() where my_name='%s'" % (self.my_name)) > > > 2.non working update() from Alchemy: > > s = aliased(MyTable) > > query = self.session.query(s).filter(s.my_name==self.my_name) > > sts = self.session.execute(query).fetchone() > > sts.update(values={'status':'L'}) > > > sts.update(values={s.status:'L'}) > > File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", > > line 2097, in _key_fallback > > "Could not locate column in row for column '%s'" % key) > > sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for > > column 'update'" > > > But Column s.status exists ... > > appreciate any help, > > --vs > > In your example, 'sts' represents a single row from the database. These > objects don't have an 'update' method, which is why you are getting that > error. It thinks you are trying to access a column called 'update' > instead. > > You appear to be using the SQL Expression language (ie. MyTable is > created using sqlalchemy.Table). You can create an 'update' statement > using MyTable.update(). Examples are at: > > http://www.sqlalchemy.org/docs/core/tutorial.html#inserts-and-updates > > (You should be able to substitute conn.execute() with session.execute()) > > However, you might be interested in using the ORM part of SQLAlchemy: > > http://www.sqlalchemy.org/docs/orm/tutorial.html > > Your usage would then look something like this (assuming MyMappedClass > is the class mapped to MyTable): > > s = MyMappedClass > query = self.session.query(s).filter(s.my_name == self.my_name) > sts = query.first() > sts.status = 'L' > self.session.flush() > > Hope that helps, > > Simon
-- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@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.