public inbox for [email protected]
help / color / mirror / Atom feedFrom: Bruno Wolff III <[email protected]>
To: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: Can any_value be used like first_value in an aggregate?
Date: Tue, 25 Jun 2024 14:11:57 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
On Tue, Jun 25, 2024 at 13:08:45 -0400,
Tom Lane <[email protected]> wrote:
>
>Not really. It will work that way in simple cases, but I think the
>behavior stops being predictable if the input gets large enough to
>induce the planner to use parallel aggregation. In any case, the
>example shown isn't amazingly efficient since it'll still perform
>a sort to meet the ORDER BY spec.
Thanks.
>> 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.
>
>Use window functions (i.e. first_value). This is what they're for,
>and they are smart enough to do just one sort for functions sharing
>a common window spec.
If I do that, I'd need to do it as a subselect inside of a group by. I'm
thinking distinct on may work and be a better way to do it. The actual
use case is a set of tripplets returned from a query, where I want on
row for each distinct value in the first column, paired with the value
in the second column, for which the third column is the largest. The
second and third columns are effectively dependent on each other, so there
won't be any ambiguity.
Thanks for getting me thinking about some other ways to approach the problem.
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Can any_value be used like first_value in an aggregate?
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox