Re: BUG #2483: Wrong error report about missing entry in from clause - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #2483: Wrong error report about missing entry in from clause
Date
Msg-id 10807.1150516470@sss.pgh.pa.us
Whole thread Raw
In response to BUG #2483: Wrong error report about missing entry in from clause  ("Klaus Guntermann" <guntermann.kl@pvw.tu-darmstadt.de>)
List pgsql-bugs
"Klaus Guntermann" <guntermann.kl@pvw.tu-darmstadt.de> writes:
> with the following simplified example I get a false error message in the
> second select statement, which is almost like the first one.

> select dummy.myfield from dummy where dummy.myfield=1 union
> select dummy.myfield from dummy where dummy.myfield=2 order by
> dummy.myfield;

It's complaining about the invalid qualification of the ORDER BY item.
An ORDER BY attached to a UNION can only use unqualified column names of
the UNION result (ie, it should just be "ORDER BY myfield" or "ORDER BY
1").  I agree that "missing FROM-clause entry" isn't the best possible
error message for that, but it doesn't look simple to improve it.

FWIW, CVS tip (8.2 to be) gives an error cursor pointing at the ORDER BY
item:

regression=# select dummy.myfield from dummy where dummy.myfield=1 union
regression-# select dummy.myfield from dummy where dummy.myfield=2 order by
regression-# dummy.myfield;
ERROR:  missing FROM-clause entry for table "dummy"
LINE 3: dummy.myfield;
        ^
regression=#

which should help at least a little.

            regards, tom lane

pgsql-bugs by date:

Previous
From: SAKATA Tetsuo
Date:
Subject: Re: BUG #2480: Installation Error of RMP for RHEL4
Next
From: "Yu-Lung Shao"
Date:
Subject: BUG #2484: pg_dump not support < redirect