Skip to content

FILTER does not handle NULLs correctly #22067

@neilconway

Description

@neilconway

Describe the bug

> SELECT g, COUNT(a) FILTER (WHERE b < 1) AS count_a
FROM (VALUES (0, 1, CAST(NULL AS INT)), (0, 2, 2)) AS t(g, a, b)
GROUP BY g;
+---+---------+
| g | count_a |
+---+---------+
| 0 | 1       |
+---+---------+
1 row(s) fetched.
Elapsed 0.016 seconds.

This is incorrect; Postgres returns 0, 0 because no rows pass the filter. DF looks at the two-valued boolean result of the filter (true/false) and doesn't check the NULL bitmap.

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions