aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2022-08-31 22:19:06 -0400
committerBruce Momjian <bruce@momjian.us>2022-08-31 22:19:06 -0400
commit6a27e2f5339479debb6ac79c2dfcdbf7f8bc695c (patch)
treef905bf9ec26ab9b2fe19eaa8f182c30f5b57490e
parent8dc12a9b64e9e2f49bcbc52fd69e7296529ff315 (diff)
downloadpostgresql-6a27e2f5339479debb6ac79c2dfcdbf7f8bc695c.tar.gz
postgresql-6a27e2f5339479debb6ac79c2dfcdbf7f8bc695c.zip
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
-rw-r--r--doc/src/sgml/query.sgml13
1 files changed, 7 insertions, 6 deletions
diff --git a/doc/src/sgml/query.sgml b/doc/src/sgml/query.sgml
index 71d644f4323..9046d7c9fbe 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 <literal>HAVING</literal>:
+ rows using <literal>HAVING</literal> and the output count using
+ <literal>FILTER</literal>:
<programlisting>
-SELECT city, max(temp_lo)
+SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo &lt; 30)
FROM weather
GROUP BY city
HAVING max(temp_lo) &lt; 40;
</programlisting>
<screen>
- city | max
----------+-----
- Hayward | 37
+ city | max | count
+---------+-----+-------
+ Hayward | 37 | 5
(1 row)
</screen>
@@ -748,7 +749,7 @@ SELECT city, max(temp_lo)
names begin with <quote><literal>S</literal></quote>, we might do:
<programlisting>
-SELECT city, max(temp_lo)
+SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo &lt; 30)
FROM weather
WHERE city LIKE 'S%' -- <co id="co.tutorial-agg-like"/>
GROUP BY city