Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rY1mz-00DvDf-Rm for pgsql-admin@arkaria.postgresql.org; Thu, 08 Feb 2024 10:37:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rY1my-00GgKA-QB for pgsql-admin@arkaria.postgresql.org; Thu, 08 Feb 2024 10:37:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rY1my-00GgK2-Br for pgsql-admin@lists.postgresql.org; Thu, 08 Feb 2024 10:37:52 +0000 Received: from mout.gmx.net ([212.227.17.20]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rY1mv-005hLV-MG for pgsql-admin@lists.postgresql.org; Thu, 08 Feb 2024 10:37:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1707388666; x=1707993466; i=shammat@gmx.net; bh=1jW4EMfXwq2DvqiU4wPOxP/W7Optxc4rOoLpl1FEeAo=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=ZDQluowludOnps5L8TsWAGu/uR37G9Z8uiG3YBSyuH7yq4W73oQDeyqzsVmTQQja dBhIiLAwJQIGCvDFwNQXLcM4Q4kAEx+QYvQGxGsrhKGSeYObA1BFzwShJVNcFNSpE lcrMM8FN9R3VHGEuO9/TNgYLpsGU/P/TkW5fZcm+vwQQVujxqKoctb8QVdXumwUzf AZuLaYvpIrhSYQ2tIScckATpzNzLjPdSVERhSDwYeWAOlTyhB4I/M+t8SU7T5hVsx xPV35svkn8aPWcFMO4V/K4JCCBJq/JdQkaoh5boa7oMfqCbyEuNyxzWeFx2bzbZRp QWB08ECBPW5SUPTgeQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [10.8.0.152] ([185.40.248.10]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N8XU1-1qucTD2blB-014Rjv for ; Thu, 08 Feb 2024 11:37:46 +0100 Message-ID: Date: Thu, 8 Feb 2024 11:37:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Need help to implement Primary Key. Content-Language: de-DE To: pgsql-admin@lists.postgresql.org References: From: Thomas Kellerer In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:1cfiImWSfnBzlJhrLc6M0/ewpPl1P1VjrJUt9Dp2YrGvVZ0mTV4 XLnJlU56CATqWreo3i+/tBd2o3HaPgqWZ9PdCBfFwgm1HX0ZdfPPU12NNQOgrTkVjvVD2bz kk+6L6JFDFWw8k2BctyAOQ7B1419vzivUo9xe0NhWxBdC67hTMrZh9iI6Lp/z3ebi7gwFdM gamgX74oLEs6sMm6/UiiQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:8ayR0718nAg=;b9Ep9+MgmlFFEZb6coNErCiezMe awIagPzOT8emOTYv576vQiXP1Vq23YxLo/8Rfm5GmQ2is78Xafjqa/y2hsoZUKhE42u6YhuBM NUoVRPK27L3WnxLPl3NpQxezwMKeO/uSbSKvdUlTEo3/lsFnv9bOjVO9fluoY7ak25j6VfYSP iagvvkVylijWBQM5AEhimw0wqlwPo9GH0e+oGf9TaF1CcJgXLPvlpl+my3mrhlYJzpaao/Q2i CUkICnwNVho4ICuEc0Fs4AeNleB1RGGRBRbYPIThynzoqFsSeZo7LZOEZ2GkTbwMntuacn1ab WLcP89YO71GdtFhq2t/1BsPOI+0pECUOwk0wTpTquk2MOcR14J9fNG21+6s6AfTc8hkiIaEkH aopTKpe3fJg4sB/EW8J5GYU5i3DUvlriH5SxQSuoEowkFEIKWP73DjvxZUkxZzWOIVsIoSD3P 0QusUpaudhagAOMHWLpI2NXjot3a6PB0NOJfoBaUjWYIHxueq1LHG741CFxe56ltNfRbxZEC6 1SowJDFtLdHNavSUny8x/4ONlGgarigKeCUzJcQ552CL/CMh/tGtLVKb3CJ4Y8gI9kZLOmPVb myHF7cK2pa4u39mj9STFguXhvL/+Xx9t2LnMncFyT2591lG0C8nFXCViwKkhYek27M9DDGc88 qzSi+OjUq8rgd4x/5gPmHhBZh+m2RaGJe65V/KGVRNcokGg+rP9bkaxJRHf1vvQBGE1btzMQy AmMyukNfE60BFQ45h9lg6bGI83WEmzKTKvghnUnYLetDg88BY5hPCYImxbcQIzv2hqe5QXI/R oL2ea46EVrOyIisDONuAlKwcZprmb3GIXg+NJ48JHOeZ8= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Gambhir Singh schrieb am 08.02.2024 um 11:30: > I have a table with a record count of ~500 million (496,098,390). > There is no primary key in this table. Now I need to set up a primary > key on this table. I can't find a way to set up a primary key. I > tried to add a new column with IDENTITY but it is not allowing null > value for existing rows and I don't know how to update the unique > value for existing records. If you add an identity column, it will automatically be populated alter table foo add id bigint generated always as identity not null; Once that has finished (which will take some time given the size of the ta= ble), you can add the primary key: alter table foo add constraint pk_foo primary key (id);