Re: [sqlalchemy] check for None with == , within join, raises argument error
Jonathan, Thank you. .op() seems to have done the trick. I'm going to go with it as of now. Thanx, Rajesh On Monday, February 5, 2018 at 2:55:50 AM UTC+5:30, Jonathan Vanasco wrote: > > > > On Sunday, February 4, 2018 at 11:07:49 AM UTC-5, Mike Bayer wrote: >> >> You test for NULL with == None. I have no idea what your issue is can >> you please share complete mappings, complete stack trace and a reproducible >> example? Thanks >> > > This definitely needs a reproduction testcase to find the correct error as > Mike noted, but if you're stuck in a bind for a temporary fix you can try: > >User.flag.op('IS')(None) > > > using `.op()` has gotten me out of a lot of problems. > > you should also check the sql emitted, because you may need to > '.self_group()' the or_ elements. > > or_(User.flag == None, User.flag != "dnd").self_group() > > > i haven't been able to create a reliable test case for the above, but > there are a handful of times in postgres queries where my or's haven't been > grouped as expected, leading to a bad query. i check everything now. > >> -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Re: SQLAlchemy - Bulk update using sqlalchemy core table.update() expects all columns in the values data
Mike, Thanx for your reply. I'll try out the 3rd option. It would still be better than updating record by record at object level. Thanx, Rajesh On Wednesday, September 28, 2016 at 1:59:38 PM UTC+5:30, Rajesh Rolo wrote: > > I'm trying to do a bulk update using core SQLAlchemy to a postgres > database. bulk_update_mappings does not work (reports StaleDataError). So > I'm trying to use core functions to do a bulk update. This works fine when > the update data passed to the values have all the columns in the db but > fails to work when we update only a certain columns. In my application, > during periodic syncs between the server and the client only a few of the > columns will get updated most of the times. > > The code snippet I have for update is : > > conn = session.connection() > table = table_dict[table_key].__table__ > stmt=table.update().where(and_(table.c.user_id==bindparam('uid'), > tbl_pk[table_key]==bindparam('pkey'))).values() > conn.execute(stmt, update_list) > > Since I update multiple tables on every sync, table names and primary keys > are indexed through an array. For the example below table_dict[table_key] > would translate to the table 'nwork' and tbl_pk[table_key] would translate > to 'table.c.nwid' which would be 'nwork.nwid'. > > The update_list is a list of records (that need to get updated) as a > python dictionary. When the record has values for all the columns it works > fine and when only some of the columns is getting updated it's throwing the > following error: > > StatementError: (sqlalchemy.exc.InvalidRequestError) A value is required > for bind parameter 'last_sync', in parameter group 1 > [SQL: u'UPDATE nwork SET type=%(type)s, name=%(name)s, > last_sync=%(last_sync)s, > update_time=%(update_time)s, status=%(status)s, > total_contacts=%(total_contacts)s, > import_type=%(import_type)s, cur_index=%(cur_index)s WHERE > nwork.user_id = %(uid)s AND nwork.nwid = %(pkey)s'] > > In this case the error was happening for a record where the column > 'last_sync' was not getting updated. > > What's the way of doing a bulk update where the records may not have all > the columns (the same set of them) getting updated? > > > I'm running SQLAlchemy 1.0.14. > -- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] SQLAlchemy - Bulk update using sqlalchemy core table.update() expects all columns in the values data
I'm trying to do a bulk update using core SQLAlchemy to a postgres database. bulk_update_mappings does not work (reports StaleDataError). So I'm trying to use core functions to do a bulk update. This works fine when the update data passed to the values have all the columns in the db but fails to work when we update only a certain columns. In my application, during periodic syncs between the server and the client only a few of the columns will get updated most of the times. The code snippet I have for update is : conn = session.connection() table = table_dict[table_key].__table__ stmt=table.update().where(and_(table.c.user_id==bindparam('uid'), tbl_pk[table_key]==bindparam('pkey'))).values() conn.execute(stmt, update_list) Since I update multiple tables on every sync, table names and primary keys are indexed through an array. For the example below table_dict[table_key] would translate to the table 'nwork' and tbl_pk[table_key] would translate to 'table.c.nwid' which would be 'nwork.nwid'. The update_list is a list of records (that need to get updated) as a python dictionary. When the record has values for all the columns it works fine and when only some of the columns is getting updated it's throwing the following error: StatementError: (sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'last_sync', in parameter group 1 [SQL: u'UPDATE nwork SET type=%(type)s, name=%(name)s, last_sync=%(last_sync)s, update_time=%(update_time)s, status=%(status)s, total_contacts=%(total_contacts)s, import_type=%(import_type)s, cur_index=%(cur_index)s WHERE nwork.user_id = %(uid)s AND nwork.nwid = %(pkey)s'] In this case the error was happening for a record where the column 'last_sync' was not getting updated. What's the way of doing a bulk update where the records may not have all the columns (the same set of them) getting updated? I'm running SQLAlchemy 1.0.14. -- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.