count() counts ROW values that are NULL

From: Erwin Brandstetter <brsaweda(at)gmail(dot)com>
To: pgsql-docs <pgsql-docs(at)postgresql(dot)org>
Subject: count() counts ROW values that are NULL
Date: 2022-03-18 20:58:15
Message-ID: CAGHENJ6fxanftiWOf9-ZJKA4bQ5v97YH0YWzDKfv6Mvw8ZPtkg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-AGGREGATE-TABLE

The manual says:

count ( "any" ) → bigint
>
> Computes the number of input rows in which the input value is not null.
>

But ROW values or composite types that "are null" are counted, anyway. See:

*db<>fiddle [here](
https://dbfiddle.uk/?rdbms=postgres_14&fiddle=7364f3f582322ac687b39c677826a074)*

Feels like a bug, but I cannot imagine how this would have slipped
everybody's attention for so long. It should at least be documented. Maybe:

Computes the number of input rows in which the input value is not a plain
NULL value. (Composite or ROW values count in any case - even if value IS
NULL evaluates to true.)

Regards
Erwin

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2022-03-18 21:28:28 Re: count() counts ROW values that are NULL
Previous Message Shinya Kato 2022-03-17 08:56:58 Re: Question about role attributes docs