重复的键值违反了唯一约束"A_users_pkey".详细信息:密钥(A_name)=(1)已存在 [英] Duplicate key value violates unique constraint "A_users_pkey" Detail: Key (A_name)=(1) already exists
问题描述
我正在尝试使用逗号分隔符插入字符串值,并且效果很好
I'm trying to insert a string Value with comma separators and it works fine
INSERT INTO users VALUES (133141214,regexp_split_to_table('rock,jackel', ','));
但是我的表具有pkey限制用户名.当我尝试按如下方式插入另一个String值
but my table has pkey Constraint to user name.When I Try to insert another String Value as follow
INSERT INTO users VALUES (144141214,regexp_split_to_table('rock,raffel', ','));
我的查询中有一个新值raffel.该raffel应该进入表,但是由于pkey,查询失败并说
Duplicate key value violates unique constraint "A_users_pkey" Detail: Key (rock_name)=(1) already exists.
My query has new value raffel in it.that raffel should enter into table but because of pkey the query is failing and saying
Duplicate key value violates unique constraint "A_users_pkey" Detail: Key (rock_name)=(1) already exists.
如何解决此问题并将Raffel插入表格?
How solve this and insert Raffel into table?
预先感谢
推荐答案
您好,据我所知,您正在尝试仅使用一条INSERT语句插入两行.
Hello as I understand from your question, you are trying to insert 2 rows with only one INSERT statement.
解决方案应该是使用两个 INSERT
语句或更改您的语句:
The solution should be either to use two INSERT
statements or to change your statement:
INSERT INTO users VALUES (regexp_split_to_table('144141214,144141215', ',')::bigint,regexp_split_to_table('rock,raffel', ','));
但是我不明白为什么你会首先这样做.
But I don't understand why would you be doing this in the first place.
这篇关于重复的键值违反了唯一约束"A_users_pkey".详细信息:密钥(A_name)=(1)已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!