From fede15417225c08479fc6cd10812a25826c65f86 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 31 Aug 2022 22:19:06 -0400 Subject: [PATCH] doc: use FILTER in aggregate example Reported-by: michal.palenik@freemap.sk Discussion: https://postgr.es/m/163499710897.684.7420075366995883688@wrigleys.postgresql.org Backpatch-through: 10 --- doc/src/sgml/query.sgml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/src/sgml/query.sgml b/doc/src/sgml/query.sgml index 6f31a5a1d6..8243bf51af 100644 --- a/doc/src/sgml/query.sgml +++ b/doc/src/sgml/query.sgml @@ -726,19 +726,20 @@ SELECT city, max(temp_lo) which gives us one output row per city. Each aggregate result is computed over the table rows matching that city. We can filter these grouped - rows using HAVING: + rows using HAVING and the output count using + FILTER: -SELECT city, max(temp_lo) +SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo < 30) FROM weather GROUP BY city HAVING max(temp_lo) < 40; - city | max ----------+----- - Hayward | 37 + city | max | count +---------+-----+------- + Hayward | 37 | 5 (1 row) @@ -748,7 +749,7 @@ SELECT city, max(temp_lo) names begin with S, we might do: -SELECT city, max(temp_lo) +SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo < 30) FROM weather WHERE city LIKE 'S%' -- GROUP BY city