views:

111

answers:

1

I'm trying to insert items into my postgres table via PHP

But get the following error message ERROR: duplicate key violates unique constraint "search6_idx1"

search6_idx1 is the index table for search6. I tried the following select setval('search6',45) and somehow that only works for sequences.

Is there any way to solve this error?

+2  A: 

When you define an index you can optionally make it UNIQUE. Such indexes serve a double purpose:

  • Speed up queries
  • Prevent duplicates

In your case, it seems that the problem is one of these:

  • You are inserting values that already exist
  • Your index is UNIQUE by mistake

The respective solutions would be:

  • Don't insert dupes
  • Make a non-unique index
Álvaro G. Vicario