Re: ANY_VALUE aggregate

2023-02-22 Thread Peter Eisentraut
On 09.02.23 10:42, Vik Fearing wrote: v4 attached.  I am putting this back to Needs Review in the commitfest app, but these changes were editorial so it is probably RfC like Peter had set it.  I will let you be the judge of that. I have committed this. I made a few small last-minute tweaks:

Re: ANY_VALUE aggregate

2023-02-14 Thread Maciek Sakrejda
I could have used such an aggregate in the past, so +1. This is maybe getting into nit-picking, but perhaps it should be documented as returning an "arbitrary" value instead of a "non-deterministic" one? Technically the value is deterministic: there's a concrete algorithm specifying how it's selec

Re: ANY_VALUE aggregate

2023-02-09 Thread Vik Fearing
On 1/23/23 08:50, David Rowley wrote: On Thu, 19 Jan 2023 at 06:01, Vik Fearing wrote: Thank you for the review. Attached is a new version rebased to d540a02a72. I've only a bunch of nit-picks, personal preferences and random thoughts to offer as a review: 1. I'd be inclined *not* to mentio

Re: ANY_VALUE aggregate

2023-01-22 Thread David Rowley
On Thu, 19 Jan 2023 at 06:01, Vik Fearing wrote: > Thank you for the review. Attached is a new version rebased to d540a02a72. I've only a bunch of nit-picks, personal preferences and random thoughts to offer as a review: 1. I'd be inclined *not* to mention the possible future optimisation in:

Re: ANY_VALUE aggregate

2023-01-19 Thread Peter Eisentraut
On 18.01.23 18:01, Vik Fearing wrote: On 1/18/23 16:06, Peter Eisentraut wrote: On 05.12.22 21:18, Vik Fearing wrote: On 12/5/22 15:57, Vik Fearing wrote: The SQL:2023 Standard defines a new aggregate named ANY_VALUE.  It returns an implementation-dependent (i.e. non-deterministic) value from

Re: ANY_VALUE aggregate

2023-01-18 Thread Vik Fearing
On 1/18/23 16:06, Peter Eisentraut wrote: On 05.12.22 21:18, Vik Fearing wrote: On 12/5/22 15:57, Vik Fearing wrote: The SQL:2023 Standard defines a new aggregate named ANY_VALUE.  It returns an implementation-dependent (i.e. non-deterministic) value from the rows in its group. PFA an implem

Re: ANY_VALUE aggregate

2023-01-18 Thread Vik Fearing
On 1/18/23 16:55, Tom Lane wrote: Peter Eisentraut writes: On 05.12.22 21:18, Vik Fearing wrote: On 12/5/22 15:57, Vik Fearing wrote: The SQL:2023 Standard defines a new aggregate named ANY_VALUE.  It returns an implementation-dependent (i.e. non-deterministic) value from the rows in its grou

Re: ANY_VALUE aggregate

2023-01-18 Thread Tom Lane
Peter Eisentraut writes: > On 05.12.22 21:18, Vik Fearing wrote: >> On 12/5/22 15:57, Vik Fearing wrote: >>> The SQL:2023 Standard defines a new aggregate named ANY_VALUE.  It >>> returns an implementation-dependent (i.e. non-deterministic) value >>> from the rows in its group. > Since the tran

Re: ANY_VALUE aggregate

2023-01-18 Thread Peter Eisentraut
On 05.12.22 21:18, Vik Fearing wrote: On 12/5/22 15:57, Vik Fearing wrote: The SQL:2023 Standard defines a new aggregate named ANY_VALUE.  It returns an implementation-dependent (i.e. non-deterministic) value from the rows in its group. PFA an implementation of this aggregate. Here is v2 of

Re: ANY_VALUE aggregate

2022-12-08 Thread Vik Fearing
On 12/8/22 06:48, David G. Johnston wrote: On Wed, Dec 7, 2022 at 10:00 PM Vik Fearing wrote: On 12/7/22 04:22, David G. Johnston wrote: On Mon, Dec 5, 2022 at 10:40 PM Vik Fearing wrote: On 12/6/22 05:57, David G. Johnston wrote: On Mon, Dec 5, 2022 at 9:48 PM Vik Fearing wrote: I

Re: ANY_VALUE aggregate

2022-12-07 Thread David G. Johnston
On Wed, Dec 7, 2022 at 10:00 PM Vik Fearing wrote: > On 12/7/22 04:22, David G. Johnston wrote: > > On Mon, Dec 5, 2022 at 10:40 PM Vik Fearing > wrote: > > > >> On 12/6/22 05:57, David G. Johnston wrote: > >>> On Mon, Dec 5, 2022 at 9:48 PM Vik Fearing > >> wrote: > >>> > I can imagine an

Re: ANY_VALUE aggregate

2022-12-07 Thread Vik Fearing
On 12/7/22 04:22, David G. Johnston wrote: On Mon, Dec 5, 2022 at 10:40 PM Vik Fearing wrote: On 12/6/22 05:57, David G. Johnston wrote: On Mon, Dec 5, 2022 at 9:48 PM Vik Fearing wrote: I can imagine an optimization that would remove an ORDER BY clause because it isn't needed for any ot

Re: ANY_VALUE aggregate

2022-12-07 Thread David G. Johnston
On Wed, Dec 7, 2022 at 1:58 AM Pantelis Theodosiou wrote: > On Tue, Dec 6, 2022 at 4:57 AM David G. Johnston > wrote: > ... > > > > > > I'm referring to the query: > > > > select any_value(v order by v) from (values (2),(1),(3)) as vals (v); > > // produces 1, per the documented implementation-d

Re: ANY_VALUE aggregate

2022-12-07 Thread Pantelis Theodosiou
On Tue, Dec 6, 2022 at 4:57 AM David G. Johnston wrote: ... > > > I'm referring to the query: > > select any_value(v order by v) from (values (2),(1),(3)) as vals (v); > // produces 1, per the documented implementation-defined behavior. > > Someone writing: > > select any_value(v) from (values (2)

Re: ANY_VALUE aggregate

2022-12-06 Thread David G. Johnston
On Mon, Dec 5, 2022 at 10:40 PM Vik Fearing wrote: > On 12/6/22 05:57, David G. Johnston wrote: > > On Mon, Dec 5, 2022 at 9:48 PM Vik Fearing > wrote: > > > >> I can imagine an optimization that would remove an ORDER BY clause > >> because it isn't needed for any other aggregate. > > > > > > I'

Re: ANY_VALUE aggregate

2022-12-05 Thread Vik Fearing
On 12/6/22 05:57, David G. Johnston wrote: On Mon, Dec 5, 2022 at 9:48 PM Vik Fearing wrote: I can imagine an optimization that would remove an ORDER BY clause because it isn't needed for any other aggregate. I'm referring to the query: select any_value(v order by v) from (values (2),(1),(

Re: ANY_VALUE aggregate

2022-12-05 Thread David G. Johnston
On Mon, Dec 5, 2022 at 9:48 PM Vik Fearing wrote: > On 12/6/22 05:22, David G. Johnston wrote: > > On Mon, Dec 5, 2022 at 8:46 PM Vik Fearing > wrote: > > > >> On 12/5/22 18:56, David G. Johnston wrote: > >>> Also, maybe we should have any_value do something like compute a 50/50 > >>> chance tha

Re: ANY_VALUE aggregate

2022-12-05 Thread Vik Fearing
On 12/6/22 05:22, David G. Johnston wrote: On Mon, Dec 5, 2022 at 8:46 PM Vik Fearing wrote: On 12/5/22 18:56, David G. Johnston wrote: Also, maybe we should have any_value do something like compute a 50/50 chance that any new value seen replaces the existing chosen value, instead of simply

Re: ANY_VALUE aggregate

2022-12-05 Thread David G. Johnston
On Mon, Dec 5, 2022 at 8:46 PM Vik Fearing wrote: > On 12/5/22 18:56, David G. Johnston wrote: > > Also, maybe we should have any_value do something like compute a 50/50 > > chance that any new value seen replaces the existing chosen value, > instead > > of simply returning the first value all th

Re: ANY_VALUE aggregate

2022-12-05 Thread Isaac Morland
On Mon, 5 Dec 2022 at 22:52, Vik Fearing wrote: > On 12/5/22 20:31, Corey Huinker wrote: > > > > Adding to the pile of wanted aggregates: in the past I've lobbied for > > only_value() which is like first_value() but it raises an error on > > encountering a second value. > > I have had use for thi

Re: ANY_VALUE aggregate

2022-12-05 Thread Vik Fearing
On 12/5/22 20:31, Corey Huinker wrote: Adding to the pile of wanted aggregates: in the past I've lobbied for only_value() which is like first_value() but it raises an error on encountering a second value. I have had use for this in the past, but I can't remember why. What is your use case fo

Re: ANY_VALUE aggregate

2022-12-05 Thread Vik Fearing
On 12/5/22 18:56, David G. Johnston wrote: Also, maybe we should have any_value do something like compute a 50/50 chance that any new value seen replaces the existing chosen value, instead of simply returning the first value all the time. Maybe even prohibit the first value from being chosen so

Re: ANY_VALUE aggregate

2022-12-05 Thread Vik Fearing
On 12/5/22 15:57, Vik Fearing wrote: The SQL:2023 Standard defines a new aggregate named ANY_VALUE.  It returns an implementation-dependent (i.e. non-deterministic) value from the rows in its group. PFA an implementation of this aggregate. Here is v2 of this patch. I had forgotten to update

Re: ANY_VALUE aggregate

2022-12-05 Thread Robert Haas
On Mon, Dec 5, 2022 at 2:31 PM Corey Huinker wrote: > Adding to the pile of wanted aggregates: in the past I've lobbied for > only_value() which is like first_value() but it raises an error on > encountering a second value. Yeah, that's another that I have hand-rolled in the past. -- Robert H

Re: ANY_VALUE aggregate

2022-12-05 Thread Corey Huinker
On Mon, Dec 5, 2022 at 12:57 PM David G. Johnston < david.g.johns...@gmail.com> wrote: > On Mon, Dec 5, 2022 at 7:57 AM Vik Fearing > wrote: > >> The SQL:2023 Standard defines a new aggregate named ANY_VALUE. It >> returns an implementation-dependent (i.e. non-deterministic) value from >> the ro

Re: ANY_VALUE aggregate

2022-12-05 Thread Robert Haas
On Mon, Dec 5, 2022 at 1:04 PM Tom Lane wrote: > "David G. Johnston" writes: > > Can we please add "first_value" and "last_value" if we are going to add > > "some_random_value" to our library of aggregates? > > First and last according to what ordering? We have those in the > window-aggregate ca

Re: ANY_VALUE aggregate

2022-12-05 Thread Tom Lane
"David G. Johnston" writes: > Can we please add "first_value" and "last_value" if we are going to add > "some_random_value" to our library of aggregates? First and last according to what ordering? We have those in the window-aggregate case, and I don't think we want to encourage people to believ

Re: ANY_VALUE aggregate

2022-12-05 Thread David G. Johnston
On Mon, Dec 5, 2022 at 7:57 AM Vik Fearing wrote: > The SQL:2023 Standard defines a new aggregate named ANY_VALUE. It > returns an implementation-dependent (i.e. non-deterministic) value from > the rows in its group. > > PFA an implementation of this aggregate. > > Can we please add "first_value