You nailed it! (it almost runs out of the box)

The only change needed is:
    return sqlalchemy.and_(*conditions) 
instead of
    return sqlalchemy.and_(conditions) 
THANK YOU!!

El martes, 26 de noviembre de 2019, 14:11:06 (UTC+1), Simon King escribió:
>
> Something like this perhaps? (untested) 
>
> def getwhereclause(table, filters): 
>     conditions = [] 
>     for colname, value in filters.items(): 
>         column = table.c[colname] 
>         conditions.append(column == value) 
>     return sqlalchemy.and_(conditions) 
>
> whereclause = getwhereclause(table, filters) 
> statement=table.update().where(whereclause).values(**datum).returning(table.c.rowid)
>  
>
>
> Hope that helps, 
>
> Simon 
>
> On Tue, Nov 26, 2019 at 12:23 PM Javier Collado Jiménez 
> <[email protected] <javascript:>> wrote: 
> > 
> > Is there an easy way to construct the where clause for update with a 
> dictionary? 
> > I'm trying 
> > 
> > 
> statement=table.update().where(**filters).values(**datum).returning(table.c.rowid)
>  
>
> > 
> > but it doesn't work. 
> > 
> > Thank you!! 
> > 
> > El miércoles, 20 de noviembre de 2019, 16:39:36 (UTC+1), Mike Bayer 
> escribió: 
> >> 
> >> 
> >> 
> >> On Wed, Nov 20, 2019, at 9:05 AM, Javier Collado Jiménez wrote: 
> >> 
> >> Hello, 
> >> 
> >> Using ORM, i'm inserting like that: 
> >> 
> >> session.add(table_mapper(**datum)) 
> >> 
> >> And updating: 
> >> 
> >> session.query(dest_table).filter_by(**filters).filter(filter_column > 
> from_date).update(datum, synchronize_session=False) 
> >> 
> >> 
> >> Is there a way to get returning rowid of the rows affected. 
> >> 
> >> I want to keep them to be used in further updates (it's really faster 
> if you use rowid in UPDATE WHERE clause) 
> >> 
> >> 
> >> you would need to construct a core UPDATE statement adding this column 
> using returning() (see 
> https://docs.sqlalchemy.org/en/13/core/dml.html?highlight=returning#sqlalchemy.sql.expression.Update.returning
>  
> ).  You might want to add it to your table definition as a "system" column 
> perhaps, not really sure.    making a system column is illustrated at 
> https://docs.sqlalchemy.org/en/13/orm/versioning.html?highlight=system#server-side-version-counters
>  
> >> 
> >> 
> >> 
> >> 
> >> -- 
> >> SQLAlchemy - 
> >> The Python SQL Toolkit and Object Relational Mapper 
> >> 
> >> http://www.sqlalchemy.org/ 
> >> 
> >> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description. 
> >> --- 
> >> 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 [email protected]. 
> >> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/cc45324e-e194-4030-b9f7-a48a36c19747%40googlegroups.com.
>  
>
> >> 
> >> 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description. 
> > --- 
> > 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 [email protected] <javascript:>. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/cbdf1b69-a0fc-41f5-a1cc-57c4fd156132%40googlegroups.com.
>  
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/016ceddb-d827-461b-b224-75b5c2634e23%40googlegroups.com.

Reply via email to