Re: Small foreign key error message improvement

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Small foreign key error message improvement
Date: 2009-07-06 20:00:18
Message-ID: 20649.1246910418@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> I recently had a puzzler, which involved this sort of accidental parser error:
> CREATE TABLE foo (a int, b text, PRIMARY KEY (a, b));

> CREATE TABLE bar (x int, y text, FOREIGN KEY (q, r) REFERENCES foo (m, n));
> ERROR: column "q" referenced in foreign key constraint does not exist

> versus

> CREATE TABLE bar (x int, y text, FOREIGN KEY (x, y) REFERENCES foo (m, n));
> ERROR: column "m" referenced in foreign key constraint does not exist

> This example has been simplified for clarity, but the original case involved a
> bunch of "id" columns everywhere. What's confusing is that "q" is not
> actually referenced by the foreign key constraint, but referenced in the
> statement that attempts to define the foreign key constraint, so I was looking
> on the wrong side of the constraint there.

> Attached is a small patch that separates those error messages into:

It seems to me that the right fix here is not so much to tweak the
message wording as to put in an error location cursor. In more
complicated cases (eg, multiple FOREIGN KEY clauses) the suggested
wording change wouldn't help much anyway.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bernd Helmle 2009-07-06 20:15:21 Re: TODO items: Alter view add column
Previous Message Stefan Kaltenbrunner 2009-07-06 19:53:35 Re: please, actualize czech link on international sites list