推荐学习书目
› 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
crytis
V2EX  ›  Python

用 SQLAlchemy 的 session 怎么执行 update 语句

  •  
  •   crytis · Oct 11, 2016 · 4226 views
    This topic created in 3679 days ago, the information mentioned may be changed or developed.

    sql 是这样的 UPDATE table_RP set send_times=send_times+1 WHERE id in (0,1,2,3),我的参数是后面 in 里面的,一个 list ,如何用 session 执行呢。我用了 session.execute(),试了好多次都不行

    3 replies  •  2016-10-11 17:35:26 +08:00
    crytis
    crytis
    OP
    Oct 11, 2016 via iPhone
    1
    目前先手动拼的 SQL😂
    lrh3321
    lrh3321
    Oct 11, 2016❤️1
    2
    session.query(table_RP).filter(table_RP.id.in_((0,1,2,3))).update({table_RP.send_times: table_RP.send_times+1})

    类似这样的写法
    crytis
    crytis
    OP
    Oct 11, 2016
    3
    @lrh3321 可以的 不过会报错 。在 update 里加上 synchronize_session='fetch' 这个就好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   724 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:48 · PVG 03:48 · LAX 11:48 · JFK 14:48
    ♥ Do have faith in what you're doing.