we dont have direct construction support for UPDATE..FROM at this
time. you can use raw SQL, or reorganize your UPDATE as a subquery
which is essentially the same thing:
update mailings set sent_ts = now(), is_done=True where mailings.id=123
and mailings_id = (select mailing_stats.mailing_id from mailings_stats
where
mailing_stats.mailing_id=mailings.id and
mailings_stats.sent_count=mailings.message_count)
On Jan 8, 2009, at 7:39 PM, mg wrote:
>
> I am trying to figure out how to do this in sqlalchemy:
>
> update mailings set sent_ts = now(), is_done=True
> from mailing_stats
> where
> mailings.id = 123
> and mailings.id = mailing_stats.mailing_id
> and mailings.message_count = mailing_stats.sent_count;
>
> Here are my tables:
>
> mailing_stats = Table('mailing_stats',metadata,
> Column('mailing_id', Integer, primary_key=True),
> Column('sent_count', Integer),
> Column('bounced', Integer)
> )
> mailings = Table('mailings',metadata,
> Column('id', Integer, primary_key=True),
> Column('start_ts', DateTime),
> Column('finish_ts', DateTime),
> Column('is_done', Integer),
> Column('message_count',Integer),
> )
>
> This is where i've gotten to in the expression language:
>
> up = mailings.update().where(mailings.c.id == 1234).values
> ({mailings.c.sent_ts:func.now(){)
> up = up.where(mailings.c.id == mailing_stats.c.mailing_id)
> up = up.where(mailings.c.message_count == mailing_stats.c.sent_count)
>
> This is the error that i get from my postgres db:
> missing FROM-clause entry for table mailing_stats
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---