From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nafees Sardar <nafees@epazz.net>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Duplicate key value violates unique constraint
Date: Mon, 16 Mar 2020 12:27:09 -0400
Message-ID: <7798.1584376029@sss.pgh.pa.us> (raw)
In-Reply-To: <000c01d5fbab$63da7be0$2b8f73a0$@epazz.net>
References: <000c01d5fbab$63da7be0$2b8f73a0$@epazz.net>
"Nafees Sardar" <nafees@epazz.net> writes:
> I migrate my data from MS Sql server to postgreSQL database, now when I try
> to insert new row it gives me error "duplicate key value violates unique
> constraint". For example I have a table which contains 100 rows of records
> when I go for inserting 101 row it give duplicate value constraint error.
> When I pass PK value manually its working, and one more thing auto increment
> is enabled for all tables .
Sounds like you need to adjust the sequence counters underlying the
auto-increment columns so that their settings are higher than any
of the already-existing ID values. Auto-increment isn't really a
native concept in Postgres, it's something you have to build from
a sequence object and a suitable default expression. Getting the
sequence set correctly is an easy step to miss when migrating from
a different DBMS.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, nafees@epazz.net
Subject: Re: Duplicate key value violates unique constraint
In-Reply-To: <7798.1584376029@sss.pgh.pa.us>
References: <000c01d5fbab$63da7be0$2b8f73a0$@epazz.net> <7798.1584376029@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox