Re: count(*) vs count(id)

Поиск
Список
Период
Сортировка
От Matt Zagrabelny
Тема Re: count(*) vs count(id)
Дата
Msg-id CAOLfK3XBUxP3jbAnKVn9cei4hh4snozhVj5yjxCipVnYvwfTsA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: count(*) vs count(id)  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: count(*) vs count(id)  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: count(*) vs count(id)  ("aNullValue (Drew Stemen)" <drew@anullvalue.net>)
Re: count(*) vs count(id)  (Guillaume Lelarge <guillaume@lelarge.info>)
Re: count(*) vs count(id)  (Laurenz Albe <laurenz.albe@cybertec.at>)
Список pgsql-general


On Mon, Feb 1, 2021 at 6:35 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Matt Zagrabelny <mzagrabe@d.umn.edu> writes:
> On Mon, Feb 1, 2021 at 5:57 PM Rob Sargent <robjsargent@gmail.com> wrote:
>> You got one null from count(*) likely.

> What is count(*) counting then? I thought it was rows.

Yeah, but count(id) only counts rows where id isn't null.

I guess I'm still not understanding it...

I don't have any rows where id is null:

$ select count(*) from call_records where id is null;
 count
═══════
     0
(1 row)

Time: 0.834 ms
$

select count(id) from call_records where id is null;
 count
═══════
     0
(1 row)

Time: 0.673 ms

Which field is count(*) counting if it is counting nulls?

-m

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: count(*) vs count(id)
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: count(*) vs count(id)