sqlalchemy 如何 执行 insert into if not exists? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 2021-09-13 10:46:22 +08:00 2243 次点击
    这是一个创建于 1564 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这种 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 条回复    2021-09-14 15:21:22 +08:00
    knightdf
        2
    knightdf  
       2021-09-14 10:39:59 +08:00
    .prefix_with('IGNORE')应该也可以解决
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     958 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 19:23 PVG 03:23 LAX 11:23 JFK 14:23
    Do have faith in what you're doing.
    ubaomsnsnddmindexpchomeyahoorakutenmypapermeadowduckbidyahooyoubaozxmzxmasdabnvcgcvbfgdfscvmmhjkxxddcyybgbzznbnccubaouaituacvGXCVETGDGYHFGBCVBFJFHCBRECBCGDGET54WRWRRWERWREWWRWERRWERSDGEWSFDSFSFfbbsubaofhddfgewrdgdfewwrewwretruyutututdfgfgdgdfgtetgdfgtdfgdert4gdfggwr235wer3wevsdfsdfgdfertxcvsdfrwerhfddfgcvbrwfafbdfhjghbmnlghrtygfdscxvxcvxcsvdasfdffgdcvsdftertsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfshasha9178shasha9178shasha9178shasha9178shasha9178liflif2liflif2liflif2liflif2liflif2liblib3liblib3liblib3liblib3liblib3zhazha444zhazha444zhazha444zhazha444zhazha444dende5dendedendendenden2denden21fenfen9fenf619fen619fenfe9fe619sdfsdfsdfsdfsdfzhazh90zhazh0zhaa50zha90zh590zhozhozzhozhzhozhozhozho2lislislls95lili95lils5liss9sdf0ty987sdft876sdft9876sdf09876sd0t9876sdf0ty98sdf0976sdf0ty986sdf0ty96sdf0t76sdf0876df0ty98sf0t876sd0ty76sdy76sdf76sdf0t76sdf0ty9sdf0ty98sdf0ty987sdf0ty98sdf6676sdf876sd876sd876sdf6sdf6sdf9876sdf0tsdf06sdf0ty9776sdf0ty9776sdf0ty76sdf8876sdf0tsd6sdf06s688876sd688sdf86
    wuwukai007
        3
    wuwukai007  
    OP
       2021-09-14 15:21:22 +08:00
    @RockShake 谢谢
    @knightdf 这个会导致自动 ID 不对