Re: SELECT MAX returns wrong value

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: SELECT MAX returns wrong value
Дата
Msg-id dcc563d10712140924h758ec6dep8129f9ef71968df9@mail.gmail.com
обсуждение исходный текст
Ответ на SELECT MAX returns wrong value  (Gavin Baumanis <gavinb@eclinic.com.au>)
Список pgsql-sql
On Dec 13, 2007 5:09 PM, Gavin Baumanis <gavinb@eclinic.com.au> wrote:
> Hi Everyone,
>
> Sorry if I am missing something obvious but I think I have found a bug.
> If I perform the following SQL
>
> SELECT MAX(column) FROM table WHERE expression
>
> and there is no match, Postgres returns a record count of 1.
> There is no value in max, it is NULL.

that's because you got one record back.  A null one, but a record none the less.

The standard way of doing this is:

select count(column) from table where expression.

since null columns don't get counted, it will return zero if they're all null.


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: odd error updating - varchar
Следующее
От: "Oleg Kharin"
Дата:
Сообщение: Bad count of rows estimated for emerge join