我使用on conflict
语句进行upsert,但收到错误:Syntax error near to line 58: ON CONFLICT (id_producto_final) DO
。
查询语句为:
Insert into table1 (id, value1, description, isactivated)
select a.id, b.value1, c.description, d.isactivated
from tableA as a
left join tableB as b on b.id=a.id1
left join tableC as c on c.id=a.id2
left join tableD as d on d.id=a.id3
ON CONFLICT (id) DO UPDATE SET isactivated= EXCLUDED.isactivated
它既不适用于do nothing
,也不会excluded table
错误。所以我猜可能会加入错误源,但我甚至不知道为什么。
有人可以帮忙吗?
答案 0 :(得分:3)
https://www.postgresql.org/docs/9.5/static/sql-insert.html
ON CONFLICT可用于指定提升a的替代动作 唯一约束或排除约束违规错误。 (见ON CONFLICT条款如下。)
https://www.postgresql.org/docs/9.4/static/sql-insert.html - 没有这样的选择。 ON CONFLICT
从9.5
https://www.postgresql.org/docs/9.5/static/release-9-5.html
PostgreSQL 9.5的主要增强功能包括:
允许转换会产生约束冲突的INSERT 进入UPDATEs或忽略