[英]ERROR: pq: there is no unique or exclusion constraint matching the ON CONFLICT specification
I have this visitor table structure like below and I have created the upsert procedure to this table.我有一个如下所示的访问者表结构,我已经为这个表创建了 upsert 过程。 When I call the procedure it returns
ERROR: pq: there is no unique or exclusion constraint matching the ON CONFLICT specification
.当我调用该过程时,它返回
ERROR: pq: there is no unique or exclusion constraint matching the ON CONFLICT specification
。 Can anyone please suggest the required changes.任何人都可以建议所需的更改。
CREATE TABLE visitors
(
id SERIAL NOT NULL,
facebook TEXT DEFAULT NULL,
github TEXT DEFAULT NULL,
linkedin TEXT NOT NULL,
twitter TEXT DEFAULT NULL
);
ALTER TABLE visitors ADD CONSTRAINT visitors_primary_key PRIMARY KEY (id);
ALTER TABLE visitors ADD CONSTRAINT visitors_urls UNIQUE (facebook, github, linkedin, twitter);
The upsert procedure:插入过程:
CREATE OR REPLACE PROCEDURE visitors_upsert
(
_facebook TEXT DEFAULT NULL,
_github TEXT DEFAULT NULL,
_linkedin TEXT DEFAULT '',
_twitter TEXT DEFAULT NULL
)
LANGUAGE SQL
AS $$
INSERT INTO visitors
(
facebook,
github,
linkedin
)
VALUES
(
_facebook,
_github,
_linkedin,
_twitter
)
ON CONFLICT (linkedin)
DO UPDATE
SET
facebook = _facebook,
github = _github,
twitter = _twitter
$$;
CALL visitors_upsert('facebook', 'github', 'linkedin', 'twitter')
Demo: https://dbfiddle.uk/?rdbms=postgres_13&fiddle=21ed4fa7526a0744feecbbe43f8944f6演示: https : //dbfiddle.uk/?rdbms=postgres_13&fiddle=21ed4fa7526a0744feecbbe43f8944f6
There is no unique constraint on linkedin
. linkedin
没有唯一约束。 Either create one, or use something else than INSERT ... ON CONFLICT
.要么创建一个,要么使用
INSERT ... ON CONFLICT
以外的其他东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.