Can any_value be used like first_value in an aggregate?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Can any_value be used like first_value in an aggregate?
Date: 2024-06-25 16:42:08
Message-ID: 20240625164208.GA1043@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-06-25 17:08:45 Re: Can any_value be used like first_value in an aggregate?
Previous Message Adrian Klaver 2024-06-25 15:42:37 Re: Postgresql python in upgraded version 16.2