Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kfAmn-000797-Nq for pgsql-general@arkaria.postgresql.org; Tue, 17 Nov 2020 23:53:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kfAmm-0004r2-Fi for pgsql-general@arkaria.postgresql.org; Tue, 17 Nov 2020 23:53:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kfAmk-0004qv-SN for pgsql-general@lists.postgresql.org; Tue, 17 Nov 2020 23:53:20 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kfAmc-0007lH-0q for pgsql-general@lists.postgresql.org; Tue, 17 Nov 2020 23:53:18 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 182CBC38; Tue, 17 Nov 2020 18:53:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 17 Nov 2020 18:53:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=w BKN/d0fm7JG9WBexk1Z9NJknxCgJ61ez8WKLrijsiY=; b=Vi2nANvmo2ZyfwxOF 8HvP4J9LX5aclbL+KLMBsiEB1VR9BprAQ7H5b7hMb+SoslAn6rU6Y7QGyvL9S7+G eLZSmEZ5dns5FwPy+qiriNcVILRYaC7jJ/TXMVUnVwBPEzXyfhAJR24Cngm9IJiB UAJHp6a65Q+peJhQYAYRnl18rObOsilwLJiZMWqRy2602JTHvYhqqbs+NbqyDKVz 5sIpD0Xp4eGg7kvEsv5Mox7grESzr7sFqZFZMgu1VwU2w2IVm70FCbRqZ92t8Qva lIV24AN4NR2HwO0DjN4IyCQSAUTGt0rqVzvSdLg9+xI1W8jZf3TzOfEFVzcWuUy/ lVjHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=wBKN/d0fm7JG9WBexk1Z9NJknxCgJ61ez8WKLrijs iY=; b=KOrG6qavlIJlG9mn3XRlYfuOHH64robIsoaw66htuuTke/LtJrpMm1oyf xfsQJV9fhEzqFHRzrIHGKjMaUWF+b7Wxffap8us/Zs3icol1sjfxLnF//j2LUO1j 4JzyZXLE+Qt98fmfbYdNsQe7uK3Zh+apCCfA7GlqFZeAMvn6w+F1FEGT+cTOV1Eg d4dhFs2kd5uPYotUK7baSdLKNNJtbtD6ckprLbIJih4xRm0oi/ysWGFlQgC/XC09 ItDYjISSjtne17jnUbt+2UAZxRgJg+/uGT8Sjw+akX757LcDXur+GzA0anA4QVBw vMIBl4akAw6VpLzGaFhvo2csndikw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefgedgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeevteejtdeikeetfefhhffhteelvdekffevudegjeeu kefhgfdvieeliedtkeevhfenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cukfhppeejhedrudejvddrudelrddufeelnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrh drtghomh X-ME-Proxy: Received: from [192.168.1.4] (75-172-19-139.tukw.qwest.net [75.172.19.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 136E93280063; Tue, 17 Nov 2020 18:53:04 -0500 (EST) Subject: Re: PK issue: serial sequence needs updating To: Rich Shepard , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Tue, 17 Nov 2020 15:53:04 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/17/20 3:46 PM, Rich Shepard wrote: > Running postgresql-12.2-x86_64-1_SBo on Slackware-14.2/x86_64. > > My restructed business database has populated tables, but the primary keys > are not aware of the current maximum number since the table rows were added > external to postgres and read in using psql. > > For example, I'm trying to add a new person to the people table which > currently has 484 rows. The insert into statement provides all columns but > the first, the PK (person_nbr) which is an int with an associated > people_person_nbr_seq. Passing the insert statement to psql is rejected > because there's already a person_nbr=1. > > How do I inform the sequence that nextval should be 485? Or, do I drop that > sequence and restore it so it reads all existing table rows and their PKs? > > If I didn't clearly explain myself, ask and I'll try again. :-) https://www.postgresql.org/docs/12/sql-altersequence.html ALTER SEQUENCE people_person_nbr_seq RESTART 485; > > TIA, > > Rich > > > > -- Adrian Klaver adrian.klaver@aklaver.com