Duplicate key value violates unique constraint “A_users_pkey” Detail: Key (A_name)=(1) already exists

南楼画角 提交于 2019-12-23 04:52:52

问题


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', ','));

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', ','));

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.

How solve this and insert Raffel into table?

Thanks in Advance


回答1:


Hello as I understand from your question, you are trying to insert 2 rows with only one INSERT statement.

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.



来源:https://stackoverflow.com/questions/35497439/duplicate-key-value-violates-unique-constraint-a-users-pkey-detail-key-a-nam

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