BUG #1188: evaluation order of select seems to be wrong

Поиск
Список
Период
Сортировка
От PostgreSQL Bugs List
Тема BUG #1188: evaluation order of select seems to be wrong
Дата
Msg-id 20040707125851.31357CF4983@www.postgresql.com
обсуждение исходный текст
Ответы Re: BUG #1188: evaluation order of select seems to be wrong  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-bugs
The following bug has been logged online:

Bug reference:      1188
Logged by:          Holger Jakobs

Email address:      holger@jakobs.com

PostgreSQL version: 7.4

Operating system:   Linux

Description:        evaluation order of select seems to be wrong

Details:

There is a table like

  create table games (
    teamnr serial,
    player integer not null,
    win    integer not null,
    lose   integer not null
  );

I have the following select statement:

  select teamnr, sum(win)/sum(lose)
  from games
  group by teamnr
  having sum(lose) > 0;

According to what I know about select, the expressions of the from clause
have to be evaluated last, so that the case that sum(lose) is zero will be
filtered _before_ the division by 0 takes place.

Unfortunately, PostgreSQL 7.4.2 gives a "division by zero" error if there
are teams which have not yet won any game. Those teams should just not
appear in the output.

Example insert statements:

insert into games values (1, 11, 3, 0);
insert into games values (1, 12, 5, 2);
insert into games values (2, 21, 6, 0);

Without the last insert everything works fine. Adding the last insert
produces a team with zero numbers of games won leading to the error.

Btw, Oracle 8 handels this correctly.

В списке pgsql-bugs по дате отправления:

Предыдущее
От: "PostgreSQL Bugs List"
Дата:
Сообщение: BUG #1187: Problem in SQL Functions on Composite Types
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: BUG #1188: evaluation order of select seems to be wrong