推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Kylin30
V2EX  ›  Python

大家用 sqlalchemy 查询是用的 filter_by 还是 filter?filter 有人说不支持组合查询是真的吗?

  •  
  •   Kylin30 · Jan 1, 2018 · 4875 views
    This topic created in 3055 days ago, the information mentioned may be changed or developed.
    filter(a == a and b==b)
    我搜了下有人说 and 后面的不生效但是也不报错,需要连续的 filter,请大佬来指点下这是真的吗?
    7 replies    2018-01-01 15:23:05 +08:00
    wb14123
        1
    wb14123  
       Jan 1, 2018
    对,这样是不生效的。可以 filter(a==a, b==b) 或 filter(and_(a==a, b==b))
    wb14123
        2
    wb14123  
       Jan 1, 2018
    其实自己试试就知道了
    Kylin30
        3
    Kylin30  
    OP
       Jan 1, 2018
    学习了,以前用了 and 没报错我以为没问题呢,现在看来要改一下了
    siteshen
        4
    siteshen  
       Jan 1, 2018
    我一般是简单的用 filter_by,filter_by 处理不了的用 filter。至于结果如何,可以配置日志看看生成的 SQL 语句。
    http://docs.sqlalchemy.org/en/latest/core/engines.html#configuring-logging



    另 @wb14123 我们似曾相识?
    wb14123
        5
    wb14123  
       Jan 1, 2018
    @siteshen 美味书签的同事?
    siteshen
        6
    siteshen  
       Jan 1, 2018
    @wb14123 对对对 @_@
    wwqgtxx
        7
    wwqgtxx  
       Jan 1, 2018 via iPhone
    因为 python 不允许重载 and 运算符,所以只能曲线救国了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1044 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 18:41 · PVG 02:41 · LAX 11:41 · JFK 14:41
    ♥ Do have faith in what you're doing.