问题
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