0

I have a table accounts_coin with unique constraint on (type, id), but it still have two rows with same value of (type, id), this image shows the problem: click

information might help:

  • postgres server version: postgres (PostgreSQL) 15.6 (Ubuntu 15.6-1.pgdg20.04+1)
  • I upgraded pg version from 9.4 to 15.6 two weeks age using pg_upgrade. I'm guessing this might be the problem, but don't know how to further look into it.

I've tried to insert another record that has the same unique value into the table, but it failed as i expected:

account=# insert into accounts_coin values ('UchihaWind', 2, 1, 0, 0, 1716860624);
ERROR:  duplicate key value violates unique constraint "accounts_coin_type_id_key"
DETAIL:  Key (type, id)=(2, UchihaWind) already exists.

Any help would be appreciated.

7
  • The id field is varchar. Is is possible that these differ by some invisible character? Like space or something? Commented May 31, 2024 at 12:42
  • @LaurenzAlbe Sorry for not describing the problem accurately, the problem is about having same values of a unique constraint btree index. Commented May 31, 2024 at 12:45
  • @freakish I guess not, cause I have queried them out by the same condition, or do you have any idea how to verify that? Commented May 31, 2024 at 13:07
  • what happens if you do id='UchihaWind'::text in your query? Commented May 31, 2024 at 13:24
  • 1
    I see. That is data corruption, possibly caused by a C library upgrade (did you upgrade the C library?). You can use the functoins in amcheck to verify that the index is broken. To fix the problem, remove all duplicate values and REINDEX the index. Commented May 31, 2024 at 13:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.