pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: jeremyevans0@gmail.com
Subject: BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta
Date: Fri, 21 Aug 2020 20:54:58 +0000
Message-ID: <16589-31c8d981ca503896@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16589
Logged by:          Jeremy Evans
Email address:      jeremyevans0@gmail.com
PostgreSQL version: 13beta3
Operating system:   OpenBSD-current
Description:        

The following SQL worked as expected in previous PostgreSQL versions (at
least 8.4-12):

  CREATE TABLE "items" ("id" integer NOT NULL, "item_id" integer NOT
NULL);
  ALTER TABLE "items" ADD UNIQUE ("item_id", "id"), ADD FOREIGN KEY ("id",
"item_id") REFERENCES "items"("item_id", "id");

In PostgreSQL 13 beta 3, it results in an error: there is no unique
constraint matching given keys for referenced table "items"

This is trivial to work around by splitting the ALTER TABLE commands:

  CREATE TABLE "items" ("id" integer NOT NULL, "item_id" integer NOT
NULL);
  ALTER TABLE "items" ADD UNIQUE ("item_id", "id");
  ALTER TABLE "items" ADD FOREIGN KEY ("id", "item_id") REFERENCES
"items"("item_id", "id");

My guess would be that the ADD FOREIGN KEY preconditions are now checked
before the ADD UNIQUE change is executed, but that isn't an educated
guess.

I'm not sure whether this is considered a bug.  It broke a couple tests for
a database access library I maintain, but I could easily modify them if this
isn't considered a bug.



view thread (2+ messages)  latest in thread

Message-ID: <16589-31c8d981ca503896@postgresql.org>
Permalink:  ../16589-31c8d981ca503896@postgresql.org/
Also on:    postgresql.org/message-id/16589-31c8d981ca503896@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, jeremyevans0@gmail.com
  Subject: Re: BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta
  In-Reply-To: <16589-31c8d981ca503896@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox