Re: [PATCH] Replace COUNT(NULL) with '0'::bigint

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Junwang Zhao <zhjwpku(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Replace COUNT(NULL) with '0'::bigint
Date: 2026-01-25 12:13:17
Message-ID: CAApHDvoaX-GGpt=KCWhGkgT=e_cYuVyLciZsGYZs3Rk+kv0S5w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, 25 Jan 2026 at 19:48, Junwang Zhao <zhjwpku(at)gmail(dot)com> wrote:
> In [1], David Rowley noted that COUNT(NULL) can be replaced
> with '0'::bigint. The change should be straightforward, and I came
> up with the attached patch to implement it.
>
> [1] https://www.postgresql.org/message-id/CAApHDvrde9DUpQ3DhPd3ia9tchVmhZqewfzxSYWmYFWVj%3DLPpg%40mail.gmail.com

Coming up with the code to do this wasn't the problem. I already
posted it in the patch in [2]. The reason I didn't commit that part is
simply that I don't think anyone would ever write COUNT(NULL) in a
query. My opinion has not changed since I wrote [3]. The main reason I
even mentioned COUNT(NULL) is because I wanted the API to support
replacing the Aggref with some other Node type, and that was the only
example I could think of to test to ensure it worked. I had hoped that
someone might come up with some ideas to do that which might be more
applicable in the real world, rather than regurgitate ideas I'd
thought of but didn't think were useful.

Do you really feel like this is useful to anyone? or did you just
write the patch because you can?

Corey did mention in [4] that he is in favour, so maybe it's just me
who thinks it's useless... Perhaps someone else wants to commit it.

David

[2] https://postgr.es/m/CAApHDvppFVDdjpYrs%3DpwgCnp-jv-tneQyfu8rWM8ymHcuJOJYw%40mail.gmail.com
[3] https://postgr.es/m/CAApHDvppFVDdjpYrs%3DpwgCnp-jv-tneQyfu8rWM8ymHcuJOJYw%40mail.gmail.com
[4] https://postgr.es/m/CADkLM%3De2Rb%2Bs3TV3LgYx8O1z2Cs%2BX2FSoafd6%3DUzpPD7hiocfw%40mail.gmail.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2026-01-25 12:42:51 Re: Make copyObject work in C++
Previous Message Alexander Lakhin 2026-01-25 12:00:00 Re: [BUG] [PATCH] pg_basebackup produces wrong incremental files after relation truncation in segmented tables