0
以下条件插入仅在项目已存在时才起作用! (不会试图插入)。PostgreSQL 9.2 - 条件插入失败,重复键冲突
如果该项不存在,我会得到重复密钥违规(重复密钥违反唯一约束)! 使用PostgreSQL 9.2
INSERT INTO mytable (mytable_handle, title, description)
select '1234/9876', 'Title here', 'description here'
from mytable where not exists
(select 1 from mytable where mytable_handle = '1234/9876')
(mytable_handle是p键)
问:'mytable_handle'是一个*字符*列?作为主键? – joop
其实我们在'1234/9876'之类的字段中使用字符串。刚刚更新了这个问题。 – pkaramol