On Jul 19, 2013, at 12:14 PM, Ed Singleton <singleto...@gmail.com> wrote:
> > > A sample script is below (bear in mind that the script contains the two > errors and I wouldn't now expect it to work anyway). OK this example is calling UPDATE towards "email_table" as the target, but then specifies the columns in "email_archive_table" in the SET clause, so that's why this doesn't work. The table referred to by UPDATE and SET need to be the same table. > > Thanks for your help. > > Ed > > ``` > import datetime > > import sqlalchemy as sa > from sqlalchemy import (String, Unicode, Integer, > DateTime, ForeignKey, Table, Column) > > metadata = sa.MetaData() > > email_table = Table("Email", metadata, > Column("id", Integer, primary_key=True), > Column("to_addr", Unicode(256), primary_key=True), > Column("subject", Unicode(256), nullable=False), > Column("lastmodifieddate", DateTime(), default=datetime.datetime.now, > onupdate=datetime.datetime.now) > ) > > email_archive_table = Table("EmailArchive", metadata, > Column("id", Integer, primary_key=True), > Column("to_addr", Unicode(256), primary_key=True), > Column("subject", Unicode(256), nullable=False), > Column("lastmodifieddate", DateTime(), default=datetime.datetime.now, > onupdate=datetime.datetime.now) > ) > > where_clause = sa.and_( > email_table.c.id==email_archive_table.c.id, > email_table.c.to_addr==email_archive_table.c.to_addr) > > update_values = dict( > [(col, None) for col in email_archive_table.columns]) > > query = email_table.update().values(update_values) > query = query.where(where_clause) > > print query > ``` > > -- > 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/groups/opt_out. > > -- 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/groups/opt_out.