Re: count(*) vs count(id)

From: "aNullValue (Drew Stemen)" <drew(at)anullvalue(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: count(*) vs count(id)
Date: 2021-02-02 01:17:50
Message-ID: 201e6c65-2d90-44f0-8b72-75cc5d9f36fd@www.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

At 2021-02-01T20:14:04-05:00, Matt Zagrabelny <mzagrabe(at)d(dot)umn(dot)edu> sent:
> 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

What you're overlooking is that, at least to my reading of your original query, id would be null for any dates that do not have any corresponding call_records (because you used a left join).

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Lelarge 2021-02-02 01:19:31 Re: count(*) vs count(id)
Previous Message David G. Johnston 2021-02-02 01:16:50 Re: count(*) vs count(id)