Re: Enhancement request: enable FIRST/LAST_value() also as a regular aggregate (not only as windowing function) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Enhancement request: enable FIRST/LAST_value() also as a regular aggregate (not only as windowing function)
Date
Msg-id 12390.1532466990@sss.pgh.pa.us
Whole thread Raw
In response to Enhancement request: enable FIRST/LAST_value() also as a regularaggregate (not only as windowing function)  (matshyeq <matshyeq@gmail.com>)
Responses Re: Enhancement request: enable FIRST/LAST_value() also as a regularaggregate (not only as windowing function)
List pgsql-hackers
matshyeq <matshyeq@gmail.com> writes:
> I'd like to throw here an enhancement proposal to discuss/consider.
> The FIRST/LAST_value()
> functions offer powerful lookup capabilities, ...
> but, given those values are repeating - why can't I simply use this
> functions as regular aggregates?
> Or can I? It doesn't seem to be possible while I find this use case
> actually more common than in windowing context…

The reason the SQL standard doesn't allow that usage, or similar ones
for other window functions, is that the function results are undefined
unless you specify a particular ordering of the inputs ... which is
exactly what the window syntax provides.

Yeah, in most cases there are other ways where you could get the same
result, but all of them require extra syntax too.  So you might as
well use window syntax and be standards-conforming.

> Anyway, Oracle is an example where both contexts are possible

Oracle is not exactly a shining example of either SQL spec compliance
or well-thought-out features ...

            regards, tom lane


pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: [HACKERS] Optional message to user when terminating/cancellingbackend
Next
From: Vik Fearing
Date:
Subject: Re: 11beta crash/assert caused by parameter type changes