推荐学习书目
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 · 4126 views
    This topic created in 3577 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
        1
    crytis  
    OP
       Oct 11, 2016 via iPhone
    目前先手动拼的 SQL😂
    lrh3321
        2
    lrh3321  
       Oct 11, 2016   ❤️ 1
    session.query(table_RP).filter(table_RP.id.in_((0,1,2,3))).update({table_RP.send_times: table_RP.send_times+1})

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