Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jDsaB-0003Nq-BN for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Mar 2020 16:27:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jDsaA-0004Gb-16 for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Mar 2020 16:27:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jDsa9-0004GU-Lm for pgsql-bugs@lists.postgresql.org; Mon, 16 Mar 2020 16:27:13 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jDsa7-0001qC-Ao for pgsql-bugs@lists.postgresql.org; Mon, 16 Mar 2020 16:27:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 02GGR9Xl007799; Mon, 16 Mar 2020 12:27:09 -0400 From: Tom Lane To: "Nafees Sardar" cc: pgsql-bugs@lists.postgresql.org Subject: Re: Duplicate key value violates unique constraint In-reply-to: <000c01d5fbab$63da7be0$2b8f73a0$@epazz.net> References: <000c01d5fbab$63da7be0$2b8f73a0$@epazz.net> Comments: In-reply-to "Nafees Sardar" message dated "Mon, 16 Mar 2020 20:55:57 +0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7797.1584376029.1@sss.pgh.pa.us> Date: Mon, 16 Mar 2020 12:27:09 -0400 Message-ID: <7798.1584376029@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Nafees Sardar" 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