Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-05-07 Thread Yaakov Bressler
That's a really interesting distinction Simon, and thank you for pointing all this out. It makes sense that anything passed to the DB would need to SQL compatible. What are your thoughts about creating functions on the DB side and executing through the ORM? Too much work for something like

Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-05-07 Thread Simon King
The point of hybrid attributes is to allow you to construct a property that can be evaluated against an instance (in which case it is "normal python"), or against a class (in which case it needs to return an SQL expression). *Sometimes* the same python code can work in both contexts, but only if

Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-05-05 Thread Yaakov Bressler
*Query would be modified to the following:* a = session.query(GeneralBeqReq)\ .filter( GeneralBeqReq.c.BeqReqStatus == 1, # this doesn't look right, but whatevz GeneralBeqReq.is_id_valid() == True, # a bit redundant, but explicit is better than implicit )\ .all()

Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-05-05 Thread Yaakov Bressler
Would it be wrong to assume that the desired function could be added as a hybrid attribute , then queried through the class obj? *Example:* from sqlalchemy.ext.hybrid import hybrid_property class *GeneralBeqReq*(Base): ...

Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-04-28 Thread Simon King
Parameters that you pass to the Query.filter function are eventually going to be rendered into an SQL statement, so your is_id_valid function probably needs to return something built from SQLAlchemy's SQL expression language: https://docs.sqlalchemy.org/en/14/core/tutorial.html If you can explain

[sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-04-27 Thread Gyanaranjan Nayak
I have a function with name is_id_valid(id) which returns either True or False. I want to pass this function inside a sqlalchemy query inside the filter condition. My query example is : a = session.query(GeneralBeqReq).filter(GeneralBeqReq.c.BeqReqStatus == 1, is_id_valid