PostgreSQL: duplicate key value violates unique constraint on UPDATE command
问题 When doing an UPDATE query, we got the following error message: ERROR: duplicate key value violates unique constraint "tableA_pkey" DETAIL: Key (id)=(47470) already exists. However, our UPDATE query does not affect the primary key. Here is a simplified version: UPDATE tableA AS a SET items = ( SELECT array_to_string( array( SELECT b.value FROM tableB b WHERE b.a_id = b.id GROUP BY b.name ), ',' ) ) WHERE a.end_at BETWEEN now() AND now() - interval '1 day'; We ensured the primary key sequence