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 1px5Z0-0008Nu-KB for pgsql-admin@arkaria.postgresql.org; Thu, 11 May 2023 12:38:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1px5Yz-00070l-7x for pgsql-admin@arkaria.postgresql.org; Thu, 11 May 2023 12:38:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1px5Yy-00070c-Sb for pgsql-admin@lists.postgresql.org; Thu, 11 May 2023 12:38:28 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1px5Yv-001kEQ-TS for pgsql-admin@postgresql.org; Thu, 11 May 2023 12:38:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=k3fG2BZglyK1O1zei5WlFss16dYtRJ6BYPRQJjUmjnc=; b=AizDbTA41vZQDQP+rWSIWX0nR9 CZtGsJIe50hugy+nBEmcJdUg7cmANsv/DuAou2lSW6cnKV/GmfdEC4uyKwrXJErEk/gqhMxtxIGs4 XYxFwRgSUnscL/WfNBlcZaPp+dt/2xc62Fa8zUbgvP8qtbixwv4K6Yf4Y/8uWgQod1bE=; Received: from depesz by depesz.com with local (Exim 4.94.2) (envelope-from ) id 1px5Ys-008MQL-0D; Thu, 11 May 2023 14:38:22 +0200 Date: Thu, 11 May 2023 14:38:21 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Wells Oliver Cc: "David G. Johnston" , pgsql-admin Subject: Re: nextval() on serial using old, existing value on insert? Message-ID: Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, May 10, 2023 at 10:06:28PM -0700, Wells Oliver wrote: > As a follow up, I've selected max(common_key) from the table and > setval()'ed on the sequence to that +1 and I think that should make this go > away. Any reason why that's insane? If you're on pg 10 or newer, you can make the id to be "generated always as identity" which will make it impossible to provide id value from user, thus making the problem impossible to happen. Best regards, depesz