Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTZpe-0005ZW-2u for pgsql-docs@arkaria.postgresql.org; Thu, 01 Sep 2022 02:21:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oTZpa-0005p7-45 for pgsql-docs@arkaria.postgresql.org; Thu, 01 Sep 2022 02:21:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTZpZ-0005ot-T6 for pgsql-docs@lists.postgresql.org; Thu, 01 Sep 2022 02:21:21 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTZpX-0003Ao-Iy for pgsql-docs@lists.postgresql.org; Thu, 01 Sep 2022 02:21:20 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1oTZpV-006rCi-1v; Wed, 31 Aug 2022 22:21:17 -0400 Date: Wed, 31 Aug 2022 22:21:17 -0400 From: Bruce Momjian To: michal.palenik@freemap.sk, pgsql-docs@lists.postgresql.org Subject: Re: nicer examples for aggregate calls Message-ID: References: <163499710897.684.7420075366995883688@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Aug 17, 2022 at 12:20:10PM -0400, Bruce Momjian wrote: > On Sat, Oct 23, 2021 at 01:51:48PM +0000, PG Doc comments form wrote: > > The following documentation comment has been logged on the website: > > > > Page: https://www.postgresql.org/docs/14/tutorial-agg.html > > Description: > > > > currently, all of the examples are very simple, like > > > > SELECT city, max(temp_lo) > > FROM weather > > WHERE city LIKE 'S%' -- (1) > > GROUP BY city > > HAVING max(temp_lo) < 40; > > > > this example would be more complex and would allow users to search for > > clause "filter": > > > > Finally, if we only care about cities whose names begin with ā€œSā€ and we want > > to calculate the number of observations in each city with temp_lo over 30, > > we might do: > > > > SELECT city, max(temp_lo), count(*) filter (temp_lo>30), > > FROM weather > > WHERE city LIKE 'S%' -- (1) > > GROUP BY city > > HAVING max(temp_lo) < 40; > > Good idea. We didn't support FILTER at the time this query was added. > Here is a patch which adds it. Patch applied back to PG 10. Thanks. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Indecision is a decision. Inaction is an action. Mark Batterson