带有 WHERE 子句的 PostgreSQL ON CONFLICT

PostgreSQL ON CONFLICT with a WHERE clause

Postgres 文档使 WHERE 子句似乎可以作为 ON CONFLICT 条件:https://www.postgresql.org/docs/9.5/static/sql-insert.html

我无法使它正常工作(如果可能的话)。这是我尝试过的众多排列之一:

INSERT INTO friends (id, dob, frn, status, "groupId", 
"createdAt", "updatedAt") 
VALUES ('1da04305-68ef-4dc1-be6c-
826ab83a6479', '1937-06-01T08:29:08-07:00', 100001, 'New', 'bc1567bc-
14ff-4ba2-b108-4cb2e0f0f768', NOW(), NOW()) 
ON CONFLICT 
    WHERE frn=100001 DO NOTHING

frn 没有任何约束,所以更简单的语法:

ON CONFLICT (frn) DO NOTHING

引发数据库错误。我希望这是一个简单的语法问题。

WHERE 子句从属于ON CONFLICT (constraint) DO UPDATE SET ... 子句。它只查看在尝试插入时违反指定约束的单行。

一个语法上有效的例子:

INSERT INTO friends (
    id, 
    dob, frn, status,
    "groupId", "createdAt", "updatedAt"
) VALUES (
    '1da04305-68ef-4dc1-be6c-826ab83a6479',
    '1937-06-01T08:29:08-07:00', 100001, 'New',
    'bc1567bc-14ff-4ba2-b108-4cb2e0f0f768', NOW(), NOW()
) 
ON CONFLICT ("groupId", frn) DO UPDATE SET
    status='Revised', 
    "updatedAt"=NOW()
WHERE friends.status<>'Deleted';

或作为 operational example