Wow Michael, this syntax is very powerfull! Two questions before I can make mistakes:
1 - the number 100 is recovered by something like len(value_list)-1, where value_list contains alls the values I want to search? 2 - id_rec for id_rec: I must to pass this in the same way you wrote? Thanks a lot and best regards Luca On Sun, Sep 29, 2013 at 5:57 PM, Michael Bayer <mike...@zzzcomputing.com>wrote: > > On Sep 29, 2013, at 10:56 AM, pyArchInit ArcheoImagineers < > pyarchi...@gmail.com> wrote: > > Hi to all. > I try to use the code in this way (query LIKE with OR operator) > > res = session.query(MAPPER).filter(or_(MAPPER.field.contains('Value1'), > MAPPER.field.contains('Value2'), MAPPER.field.contains('Value3'),MAPPER > .field.contains('Value4'))) > > With a small dataset, I found the records I want, but with a larger > dataset sqlalchemy return me an error: > > more than 255 arguments. > > To bypass this problem in the past I used the operator in_ in this way: > > id_list = [1, 2, 3] > > session.query(CLASS).filter(CLASS.field.in_(id_list)).all() > > I've guessed that was possible to make something like this: > > value_to_find = [CLASS.field.contains('value1'), > CLASS.field.contains('value2')] > > session.query(CLASS).filter(CLASS.field.in_(value_to_find)).all() > > This script runs without error, but didn't return me any result. > > Because is a OR type query, it's a good idea make single research for each > value and storing the id of every record in a list? > > Smothing like this: > > res_list = [] > for value in value_list: > res = session.query(MAPPER).filter(MAPPER.field.contains(value)) > for r in res: > res_list.append(res.id_record) > > > I'd batch them (also if you only need "id_record", query for that > specifically): > > res_list = [] > while value_list: > chunk = value_list[0:100] > value_list = value_list[100:] > res_list.extend(id_rec for id_rec, in > session.query(M.id_record).filter(or_(*[M.field.contains(v) for v in > chunk]))) > > > > > > -- https://sites.google.com/site/pyarchinit/<http://www.pyarchinit.altervista.org> pyarchinit - progetto per la gestione integrata dei dati di scavo su piattaforme GIS Free Open Suorce -- 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.