postgres: ERROR: duplicate key violates unique constraint

Problem może wystąpić np. przy przeniesieniu bazy z mysql do postgresa.

$ psql

baza=> \ds

np.

List of relations
Name | Type | Owner
—————-+———-+———
tfile_id__seq | sequence | wrobelm
tgroup_id__seq | sequence | wrobelm
tprog_id__seq | sequence | wrobelm
tuser_id__seq | sequence | wrobelm

i teraz dla każdej pary sekwencja – tabela robimy:

baza=> select max(id_) from tuser;
max
—–
82
(1 row)
baza=> select setval(‘tuser_id__seq’,82);
setval
——–
82
(1 row)

itd. itd.

Leave a Reply

Your email address will not be published. Required fields are marked *