select判断+insert插入的原子操作 pgsql

通过sql一步处理

insert into table_name(column1,column2,column3) 
select ‘value1‘,‘value2‘,‘value3‘
where not exists(select column from table_name where id=1);

 

eg:

insert into subscribe_member(openid,msg_title,can_times)
select ‘hhhh‘,‘biaoti‘,1
where not exists(select openid from subscribe_member where id=1);