On Jun 4, 2008, at 11:51 AM, Jeff Putsch wrote:

>
> Howdy,
>
> I'm trying to execute the following:
>
> nis_accounts_table.update(
>   and_(nis_accounts_table.c.domain_id == 20,
>           nis_users_table.c.id == nis_accounts_table.c.nis_user_id,
>           nis_users_table.c.expires < datetime.today()
>   )).execute(active=False)
>
> with PostgreSQL > 8.1 and sqlalchemy 0.4.6
>
> Unforutnately the SQL getting generated is:
>
> 'UPDATE nis_accounts SET active=%(active)s WHERE
> nis_accounts.domain_id = %(domain_id_1)s AND nis_users.id =
> nis_accounts.nis_user_id AND nis_users.expires < %
> (expires_1)s' {'active': False, 'expires_1': datetime.datetime(2008,
> 6, 4, 8, 43, 8, 91895), 'domain_id_1': 20}
>
> and PostgreSQL complains about a missing FROM clause for table
> nis_users.
>
> The SQL should be:
>
> 'UPDATE nis_accounts SET active=%(active)s FROM nis_users WHERE
> nis_accounts.domain_id = %(domain_id_1)s AND nis_users.id =
> nis_accounts.nis_user_id AND nis_users.expires < %
> (expires_1)s' {'active': False, 'expires_1': datetime.datetime(2008,
> 6, 4, 8, 43, 8, 91895), 'domain_id_1': 20}
>
> It is not clear to me how to get this clause added using SQLA.
>
> Do I need to use a raw SQL statement here?


SQLA's update() construct does not support "FROM" (its not standard  
SQL).  Use a subquery instead to match rows, or alternatively raw SQL  
for the PG-specific version.



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to