| From: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
|---|---|
| To: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
| Cc: | huseyin(dot)d3r(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19393: pg_upgrade fails with duplicate key violation when CHECK constraint named *_not_null exists |
| Date: | 2026-02-21 11:56:24 |
| Message-ID: | 202602211127.yhfjy43if2kk@alvherre.pgsql |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs pgsql-hackers |
On 2026-Feb-05, 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 attached patch
> > fixes the problem for me by avoiding given constraint names when generating
> > the names for NOT NULL constraints.
>
> ... and here is v2, including a regression test.
Thanks for this! I have pushed it now to 18 and master (right before
the embargo for next week's release -- not really apologizing about
that, since this is clearly something that's going to bite users as they
move up to 18). Two notes:
1. this will cause an ABI break report for AddRelationNotNullConstraints
in branch 18. I considered the idea of adding a shim function
preserving the original API, but I think this is not a function likely
to be used by third-party code. So I'll address this by adding an entry
to .abi-compliance-history instead.
2. I moved this foreach loop
> @@ -2905,6 +2907,12 @@ AddRelationNotNullConstraints(Relation rel, List *constraints,
> * system-generated name conflicts we just generate another.
> */
> nnnames = NIL;
> + foreach_ptr(CookedConstraint, cons, existing_constraints)
> + {
> + if (cons->name != NULL)
> + nnnames = lappend(nnnames, cons->name);
> + }
> +
> givennames = NIL;
from AddRelationNotNullConstraints to DefineRelation; it seems more
natural for the former to receive a list of constraint names than a list
of CookedConstraints.
Thanks Hüseyin for the report and Laurenz for the fix!
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"How strange it is to find the words "Perl" and "saner" in such close
proximity, with no apparent sense of irony. I doubt that Larry himself
could have managed it." (ncm, http://lwn.net/Articles/174769/)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Álvaro Herrera | 2026-02-21 13:45:31 | Re: BUG #19393: pg_upgrade fails with duplicate key violation when CHECK constraint named *_not_null exists |
| Previous Message | ludovitkramar | 2026-02-20 23:58:59 | BUG: SUBSTRING on TOASTed text returns "invalid byte sequence for encoding UTF8: 0xc3" |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Álvaro Herrera | 2026-02-21 13:45:31 | Re: BUG #19393: pg_upgrade fails with duplicate key violation when CHECK constraint named *_not_null exists |
| Previous Message | Alexander Korotkov | 2026-02-21 09:54:43 | Re: Odd code around ginScanToDelete |