Обсуждение: BUG #2483: Wrong error report about missing entry in from clause

Поиск
Список
Период
Сортировка

BUG #2483: Wrong error report about missing entry in from clause

От
"Klaus Guntermann"
Дата:
The following bug has been logged online:

Bug reference:      2483
Logged by:          Klaus Guntermann
Email address:      guntermann.kl@pvw.tu-darmstadt.de
PostgreSQL version: 8.1.4
Operating system:   Linux
Description:        Wrong error report about missing entry in from clause
Details:

Hi,
with the following simplified example I get a false error message in the
second select statement, which is almost like the first one. The german text
of the error message is:
FEHLER:  fehlender Eintrag in FROM-Klausel für Tabelle »dummy«
The difference is that in the second statement all columns are qualified by
the table name.
The example is simplified from a larger select and normally one would not
phrase the selection this way. But nevertheless I think both versions of the
statement should work.
Thank you very much for your work on PostgreSQL!
Best regards,
Klaus

8<------------------- cut here
create temporary table dummy (myfield integer);
insert into dummy (myfield) values (1);
insert into dummy (myfield) values (2);

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

select dummy.myfield from dummy where dummy.myfield=1 union
select dummy.myfield from dummy where dummy.myfield=2 order by
dummy.myfield;
8<------------------- cut here

Re: BUG #2483: Wrong error report about missing entry in from clause

От
Tom Lane
Дата:
"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