Postgresql中无则插入的使用方法INSERT INTO WHERE NOT EXISTS
一、问题
Postgresql中无则插入的使用方法INSERT INTO WHERE NOT EXISTS,用法请参考样例。
二、解决方案
(1)PostgresSQL
INSERT INTO test_tab(name,sex,address,lastEndTime,createTime) SELECT 'a','b','c',1,1 FROM (select 1) tmp WHERE NOT EXISTS (Select 1 FROM test_tab where name = '0')
(2)MySQL(使用系统临时表DUAL)
INSERT INTO `test_tab`(`name`,`age`,`addresss`) SELECT 'aa',2,'bb' FROM DUAL WHERE NOT EXISTS(SELECT 1 FROM `test_tab` Where name == 'aa')
(3)SQLServer
IF NOT EXISTS (SELECT id FROM books WHERE id = 1) INSERT INTO books (name) SELECT 'Songxingzhu'
宋兴柱:转载内容,请标明出处,谢谢!源文来自 宝贝云知识分享:https://www.dearcloud.cn