Proposed patch to change "missing FROM" messages - Mailing list pgsql-patches

From Tom Lane
Subject Proposed patch to change "missing FROM" messages
Date
Msg-id 22842.1136849568@sss.pgh.pa.us
Whole thread Raw
Responses Re: Proposed patch to change "missing FROM" messages
List pgsql-patches
Attached is a proposed change to create hopefully-more-useful error
messages in the cases where we currently say "missing FROM-clause entry".
Some examples of what it does:

Patch:
regression=# select * from a,b join c on (a.aa = c.cc);
ERROR:  invalid reference to FROM-clause entry for table "a"
HINT:  There is an entry for "a", but it cannot be referenced from this part of the query.
8.1:
regression=# select * from a,b join c on (a.aa = c.cc);
ERROR:  missing FROM-clause entry for table "a"
8.0:
regression=# select * from a,b join c on (a.aa = c.cc);
NOTICE:  adding missing FROM-clause entry for table "a"
ERROR:  JOIN/ON clause refers to "a", which is not part of JOIN

Patch:
regression=# select a.* from a b;
ERROR:  invalid reference to FROM-clause entry for table "a"
HINT:  Perhaps you meant to reference the table alias "b".
8.1:
regression=# select a.* from a b;
ERROR:  missing FROM-clause entry for table "a"

The above happens only because there is a table "a"; 8.1 behaves
differently when there isn't such a table:

Patch:
regression=# select nosuch.* from a b;
ERROR:  missing FROM-clause entry for table "nosuch"
8.1:
regression=# select nosuch.* from a b;
ERROR:  relation "nosuch" does not exist

(This happens because 8.1 tries to create the RTE before it does
warnAutoRange.  This change in behavior is a side-effect of having
to reorder the operations, but it doesn't seem worse to me.)

The same hints are issued as part of the NOTICE when add_missing_from
is ON, but I did not change the main text of the NOTICE messages.
Also, the error message or notice is unchanged from 8.1 if the code
can't find any RTE that the reference plausibly could have been meant
to match.

I'd like to apply this to 8.1 branch as well as HEAD.  This would
create a need for some new message translations, but there should
be time for translators to do that before 8.1.3, if they are so
inclined.

Comments?

            regards, tom lane


Attachment

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: CREATEUSER == SUPERUSER?
Next
From: Joachim Wieland
Date:
Subject: TODO-item: Add sleep() function, remove from regress.c