Re: count(*) vs count(id)

From: Matt Zagrabelny <mzagrabe(at)d(dot)umn(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Rob Sargent <robjsargent(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: count(*) vs count(id)
Date: 2021-02-02 01:14:04
Message-ID: CAOLfK3XBUxP3jbAnKVn9cei4hh4snozhVj5yjxCipVnYvwfTsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Feb 1, 2021 at 6:35 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Matt Zagrabelny <mzagrabe(at)d(dot)umn(dot)edu> writes:
> > On Mon, Feb 1, 2021 at 5:57 PM Rob Sargent <robjsargent(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-02-02 01:16:50 Re: count(*) vs count(id)
Previous Message Tom Lane 2021-02-02 00:34:58 Re: count(*) vs count(id)