Error message for FK referencing deferrable unique/PK

Started by Dean Rasheedover 16 years ago2 messageshackers
Jump to latest
#1Dean Rasheed
dean.a.rasheed@gmail.com

While looking at this report

http://archives.postgresql.org/pgsql-bugs/2009-08/msg00083.php

I spotted another error message which could use improvement:

CREATE TABLE foo(a int PRIMARY KEY DEFERRABLE);
CREATE TABLE bar(a int REFERENCES foo(a));

ERROR: there is no unique constraint matching given keys for
referenced table "foo"

Whereas if you define the FK slightly differently so that it goes
through transformFkeyGetPrimaryKey() instead, you get a much better
error message:

CREATE TABLE bar(a int REFERENCES foo);

ERROR: cannot use a deferrable primary key for referenced table "foo"

The attached patch to transformFkeyCheckAttrs() makes the former case
generate a similar error to the latter.

- Dean

Attachments:

fk-deferrable-error.patchtext/x-patch; charset=US-ASCII; name=fk-deferrable-error.patchDownload+34-18
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dean Rasheed (#1)
Re: Error message for FK referencing deferrable unique/PK

Dean Rasheed <dean.a.rasheed@googlemail.com> writes:

I spotted another error message which could use improvement:
...
The attached patch to transformFkeyCheckAttrs() makes the former case
generate a similar error to the latter.

Ah, you caught me being lazy ;-). I had actually considered doing this
while reviewing the deferrable-uniqueness patch, but ran out of energy
and did the one-liner change instead. Patch applied.

regards, tom lane