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

sqlalchemy 如何 执行 insert into if not exists?

  •  1
     
  •   wuwukai007 · Sep 13, 2021 · 2402 views
    This topic created in 1701 days ago, the information mentioned may be changed or developed.

    这种 sql,怎么用 sqlalchemy 写?

    INSERT INTO table_listnames (name, address, tele)
    SELECT * FROM (SELECT 'Rupert', 'Somewhere', '022') AS tmp
    WHERE NOT EXISTS (
        SELECT name FROM table_listnames WHERE name = 'Rupert'
    ) LIMIT 1;
    
    3 replies    2021-09-14 15:21:22 +08:00
    knightdf
        2
    knightdf  
       Sep 14, 2021
    .prefix_with('IGNORE')应该也可以解决
    wuwukai007
        3
    wuwukai007  
    OP
       Sep 14, 2021
    @RockShake 谢谢
    @knightdf 这个会导致自动 ID 不对
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   988 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 20:28 · PVG 04:28 · LAX 13:28 · JFK 16:28
    ♥ Do have faith in what you're doing.