postgresql ON CONFLICT with multiple constraints

↘锁芯ラ 提交于 2021-02-07 13:40:40

问题


There is a constraint violation handling "On conflict" statement, working fine if i want to check 1 (!) constraint

For example :

 INSERT INTO my_table (co1,col2..colN) 
 VALUES (...) 
 ON CONFLICT (col1, col2) DO NOTHING --or update

But if i have 2 constaints unique(col1,col2) and unique(col5,col6,col7) , the query below is not working :

INSERT INTO my_table (co1,col2..colN) 
VALUES (...) 
ON CONFLICT (col1, col2) DO NOTHING --or update
ON CONFLICT (col5, col6, col7) DO NOTHING --or update

This raises the error, pointing on : ERROR: syntax error at or near "on". LINE _: on conflict (col5, col6, col7) do nothing

How could i resolve using multiple constraint checking in one query?

来源:https://stackoverflow.com/questions/52236263/postgresql-on-conflict-with-multiple-constraints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!