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.96) (envelope-from ) id 1voJM7-0015tN-0C for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Feb 2026 10:46:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1voJM6-003AfR-09 for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Feb 2026 10:46:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1voJM5-003AfJ-2J for pgsql-bugs@lists.postgresql.org; Fri, 06 Feb 2026 10:46:29 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1voJM3-00000001LYZ-1YiJ for pgsql-bugs@lists.postgresql.org; Fri, 06 Feb 2026 10:46:29 +0000 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-385e7cafef9so16975361fa.0 for ; Fri, 06 Feb 2026 02:46:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770374785; cv=none; d=google.com; s=arc-20240605; b=cO+4pUFOwjoo08yF+s1n5rESPK/YOEg+5ytbcZEr+oPctn88gJU5JBMljL37aX2K2n GkPAvqDn2/eZvDise8zshttoC+zmaQpCg9/loUuXR4VllMYym45eD86e4NfPdbt41GSa CBUFv9aL6wLxHcgyGEjcCM1M9J4Nfi4UO01iMsGIrz59HeAsDXlAi2hXLtxkVK8q/eMy MeC3Pox3z8hYc5ldwGWGEj8UTItFSOZzRT1C5WjdkpsKQ8joeYmuJz8i4JbQwSAKofUX arhKGalaHYfbd+bHJp7RRWqswP+90/TiDGimEe9iCowY3BCkPkOeOt/LcE4Jksrh43gk EDyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=DY1pX1T+k9iCTrmDbrV6xDzvjoo3vzd8+twTO2FxRB0=; fh=1KmFS7e75FwiKuFN7O01oNR8hcVV5ZdP0AGzBobhDQA=; b=jQ26bDUSjJll8qFLNuGEkRrJl9buTeOApIAXF2hnksioQ8BISLx4OEPziG+AsxPaFo Xz4XuywtsBOwQB+DhwEVoQpdBb7og7U8pgROM6Fmxhi82x7KCRXAK0ztHw9ae4MpX8iw 9JA15oN042KoXN7LXANDVFd9mu8oMtZsvo+b4eIy4IT2k8BWB8Ued25twWIh8Cao/9i/ PwHYaebJewiRBnd6jlxsws6xYYfUINPGBXx5uMv5fJCUZDjd6tkpyXboeUj40iFpmEDg ahIKHlVbLVBXrEMOOddlW1sCcJ8P5+tSYiGfCdMT4NHf4G58QYF444uf3Uq6LNuGDJKD G7Ww==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770374785; x=1770979585; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DY1pX1T+k9iCTrmDbrV6xDzvjoo3vzd8+twTO2FxRB0=; b=dE3tId+z6zMCYn8IEmyK6L/DrxRywhI4aWnRarmnxSFXmbhWOnaee3NqsKRmKxMA5z g7N0KNCl74LOBoI1mHoutcb3hb5EjKDWFvWixpHOv7mfqkzLL7NegH3L7t9pIIYwYnxP f7bUZg3VbBInd8ZuzuRIjJs8fj+aRcoYGESs4VwK/dWXbX5/wSEJnBJGjApRJ7gWqD5E s2/3WCTDqxgK2wT4dNhfAx/Frow/WbdG4fkr4L4oXcq94o4kHAOvnk4/f0HTeMkkN3bs PC0qRXOk2k9K7pqU3sT5wPqvvQ+QneiS5yEEe6jmR0KJYPzl4M8kGr0eZd6nk0O6RNGy NZ7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770374785; x=1770979585; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=DY1pX1T+k9iCTrmDbrV6xDzvjoo3vzd8+twTO2FxRB0=; b=NqmmVKuiPLGJqxfgo6wHr13pBEDJOCkvBXb4OEt7krdrEhyLYzR/cx2ZN5l6wzgC0u y9v4yArGZaqFeL03ysWPbEtF229T7RFfnktQjdIMM+N7q0nBAnzWKVPFVAX0IIaQEPzB poiOt9WyjRqWf0qlDeX2KeFytjzDRfZZXaPRUoef66+rgO0R2CVC6k0FUBpr+aDTS3We 29dpWyYyLveK4saQAYaobO8rUV8GULcZdYqEyVypvnWI5LyM5OaBd8b3eKoMX27pMA4P IOWgvDcYmAp7i0iiuiOeJxTYq9UcnE0NxD3ky38QVoShKWVOpgkMCuVsYMOYWZXuvUnv B2+A== X-Forwarded-Encrypted: i=1; AJvYcCXC1OjzUwexUy7dBi58TE+EB8F46ZGFz2GjAAhFQWRGAWsJExgsaxr+Y9E252TBNQ6n3BtENUS49Wzc@lists.postgresql.org X-Gm-Message-State: AOJu0YyIlHVmn3BtsOtIXYEPz3RoAZUsGkj+CpCiwoTPjySEyGLoSSUB kYp8//WboJRh8E3uPHhtEPfnasCBa8O4VLZLcRWdh3BZZpdJ/2ptbmdeNLLOvfYNtfKFHJdBvnr HDsGlIEoi4BD8Xy0Ip+EoeBFCgLq551M= X-Gm-Gg: AZuq6aKDNnUzQUpegyb7qpHMgskIiQugkwQvGRtq0SzzVcVqZGYH8tdliUm0wRVgYve WS6cgoG1adbl7h7slGs3N84n3qwSwluyclbwyNJRWPvCCAkNeSwnH0kCMovm+a+FVCAbQWL7mBN L64OGx6pjjP/nEbHXMmEcO9REyxwKMTPHNhkKkh74xvaChP3ew0th1dn39QZH4rfOpoQHCxKNXv VnrqxPOAIIYXk3Lm1hxVNUxexJ7lObTRO87uxZeq8ShaCmtKMZIOFqJsR9LooabKEuFDrI= X-Received: by 2002:a05:6512:1554:10b0:59e:462a:3d8f with SMTP id 2adb3069b0e04-59e462a3df6mr360655e87.5.1770374784884; Fri, 06 Feb 2026 02:46:24 -0800 (PST) MIME-Version: 1.0 References: <19393-6a82427485a744cf@postgresql.org> <2b3a2cd5f9b6e82fba6ac45b413291b01dd252ea.camel@cybertec.at> <61c535617992fff830961ecc09a9c20096bc1f36.camel@cybertec.at> <99c37bcd620778c743a413dc9a1dce53ae9f4c38.camel@cybertec.at> In-Reply-To: <99c37bcd620778c743a413dc9a1dce53ae9f4c38.camel@cybertec.at> From: Dilip Kumar Date: Fri, 6 Feb 2026 16:16:08 +0530 X-Gm-Features: AZwV_QgzMJ9EkkXYjWg1kur-vlZD0Hiqp-0GaZ0lUqDBIDh_y7pnrFQIpFyoMZ4 Message-ID: Subject: Re: BUG #19393: pg_upgrade fails with duplicate key violation when CHECK constraint named *_not_null exists To: Laurenz Albe Cc: huseyin.d3r@gmail.com, pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Feb 6, 2026 at 2:40=E2=80=AFPM Laurenz Albe wrote: > > On Fri, 2026-02-06 at 12:53 +0530, Dilip Kumar wrote: > > On Thu, Feb 5, 2026 at 10:22=E2=80=AFPM Laurenz Albe wrote: > > > > > > On Thu, 2026-02-05 at 15:58 +0100, I wrote: > > > > The bug is actually not in pg_upgrade, but in CREATE TABLE. The at= tached patch > > > > fixes the problem for me by avoiding given constraint names when ge= nerating > > > > the names for NOT NULL constraints. > > > > > > ... and here is v2, including a regression test. > > > > The fix LGTM. However I have one question, have you considered > > validating the name selection logic for other constraint types as > > well? I=E2=80=99m specifically thinking about AddRelationNewConstraints= (). > > While I don't have a specific test case yet, is it possible for the > > AddRelationNewConstraints to choose a name that is already in use when > > adding a new column with a constraint? > > Thanks for having a look. > > I am not sure what you mean by "adding a new column": do you mean an > ALTER TABLE that runs after the CREATE TABLE? > > The following works fine in v18: > > CREATE TABLE nulls ( > y integer UNIQUE, > CONSTRAINT nulls_x_not_null FOREIGN KEY (y) REFERENCES nulls (y), > CONSTRAINT nulls_x_fkey CHECK (TRUE) > ); > > ALTER TABLE nulls ADD x integer REFERENCES nulls (y) NOT NULL; > > Both the new foreign key and the new NOT NULL constraint get a name > that doesn't conflict with the existing constraints. Right I see, I was talking about the similar case something like[1] but I see it already handles the conflict and generates a conflicting name if a constraint with the name already exists. So we are good, thanks. postgres[58251]=3D# CREATE TABLE two_not_null_constraints ( col integer, CONSTRAINT two_not_null_constraints_col1_check CHECK (col >= 5) ); CREATE TABLE postgres[58251]=3D# ALTER TABLE two_not_null_constraints ADD COLUMN col1 int check (col1 > 0); ALTER TABLE postgres[58251]=3D# \d+ two_not_null_constraints Table "public.two_not_null_constraints" Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description --------+---------+-----------+----------+---------+---------+-------------= +--------------+------------- col | integer | | | | plain | | | col1 | integer | | | | plain | | | Check constraints: "two_not_null_constraints_col1_check" CHECK (col > 5) "two_not_null_constraints_col1_check1" CHECK (col1 > 0) Access method: heap --=20 Regards, Dilip Kumar Google