Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sM9OP-000qd5-Ia for pgsql-general@arkaria.postgresql.org; Tue, 25 Jun 2024 16:51:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sM9OM-00GoSv-Bj for pgsql-general@arkaria.postgresql.org; Tue, 25 Jun 2024 16:51:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sM9OM-00GoSn-0r for pgsql-general@lists.postgresql.org; Tue, 25 Jun 2024 16:51:38 +0000 Received: from wolff.to ([98.103.208.27]) by makus.postgresql.org with smtp (Exim 4.94.2) (envelope-from ) id 1sM9OJ-0035P3-EN for pgsql-general@lists.postgresql.org; Tue, 25 Jun 2024 16:51:36 +0000 Received: (qmail 1083 invoked by uid 500); 25 Jun 2024 16:42:08 -0000 Date: Tue, 25 Jun 2024 11:42:08 -0500 From: Bruno Wolff III To: pgsql-general@lists.postgresql.org Subject: Can any_value be used like first_value in an aggregate? Message-ID: <20240625164208.GA1043@wolff.to> Mail-Followup-To: Bruno Wolff III , pgsql-general@lists.postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk For example, is output of 10 guaranteed in the following: bruno=> select any_value(x order by x desc) from generate_series(1,10) as x; any_value ----------- 10 (1 row) The use case is that I want to return a value of one column that is paired with the maximum value of another column in each group when using GROUP BY. (There aren't going to be any NULLs in the involved columns.) Thanks.