pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta
2+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2020-08-22 5b02d68e75 47de6ac11b  Fix ALTER TABLE's scheduling rules for AT_AddConstraint subcommands.
* BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta
@ 2020-08-21 20:54 PG Bug reporting form <noreply@postgresql.org>
  2020-08-22 16:37 ` Re: BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2020-08-21 20:54 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: jeremyevans0@gmail.com

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.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta
  2020-08-21 20:54 BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta PG Bug reporting form <noreply@postgresql.org>
@ 2020-08-22 16:37 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2020-08-22 16:37 UTC (permalink / raw)
  To: jeremyevans0@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> 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"

Yup, that's my fault; fix pushed.

> 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.

Yeah, I think it's a bug, especially since the case used to work.
ALTER TABLE generally believes that it's smarter than you are about
the order in which the subcommands need to be executed; so it has
to hold up its end of the bargain.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-08-22 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21 20:54 BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta PG Bug reporting form <noreply@postgresql.org>
2020-08-22 16:37 ` Tom Lane <tgl@sss.pgh.pa.us>

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