【发布时间】:2020-04-15 22:12:15
【问题描述】:
我正在向表中插入数据,如下所示
| num | name | value |
----------------------------------
| 1 | name1 | 1 |
| 2 | name2 | 1 |
| 3 | name3 | 1 |
| 4 | name4 | 2 |
| 5 | name5 | 3 |
我想在任意行中插入类似 insert into table (num, name, value) values(6,name,1) when (num and value together) not exist 的 where 子句
我尝试先选择并根据该结果插入,但我认为这不是我在单个查询中想要的最佳方式
尝试过:select * from the table where name=$name and value= $value if I got result then not insert otherwise insert. 它是通过两个查询完成的,但我不想要它。
如有任何帮助,将不胜感激。
【问题讨论】:
标签: sql postgresql