proposal: variadic argument support for least, greatest function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

proposal: variadic argument support for least, greatest function

Pavel Stehule
Hi

We can pass variadic arguments as a array to any variadic function. But some our old variadic functions doesn't supports this feature.

We cannot to write

SELECT least(VARIADIC ARRAY[1,2,3]);

Attached patch add this possibility to least, greatest functions.

Regards

Pavel

minmax_variadic.patch (15K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: proposal: variadic argument support for least, greatest function

Vik Fearing-4
On 08/11/2018 15:59, Pavel Stehule wrote:

> Hi
>
> We can pass variadic arguments as a array to any variadic function. But
> some our old variadic functions doesn't supports this feature.
>
> We cannot to write
>
> SELECT least(VARIADIC ARRAY[1,2,3]);
>
> Attached patch add this possibility to least, greatest functions.

Is there any particular reason you didn't just make least and greatest
actual functions?
--
Vik Fearing                                          +33 6 46 75 15 36
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support

Reply | Threaded
Open this post in threaded view
|

Re: proposal: variadic argument support for least, greatest function

Andrew Gierth
>>>>> "Vik" == Vik Fearing <[hidden email]> writes:

 >> Attached patch add this possibility to least, greatest functions.

 Vik> Is there any particular reason you didn't just make least and
 Vik> greatest actual functions?

least() and greatest() have some type unification logic that I don't
think works for actual functions.

create function s(variadic anyarray) returns anyelement
  language sql immutable
  as $$ select min(v) from unnest($1) u(v); $$;

select s(1,2,3); -- works
select s(1,2,3.0);  -- ERROR:  function s(integer, integer, numeric) does not exist
select least(1,2,3.0);  -- works

--
Andrew (irc:RhodiumToad)

Reply | Threaded
Open this post in threaded view
|

Re: proposal: variadic argument support for least, greatest function

Pavel Stehule
In reply to this post by Vik Fearing-4


so 10. 11. 2018 v 19:12 odesílatel Vik Fearing <[hidden email]> napsal:
On 08/11/2018 15:59, Pavel Stehule wrote:
> Hi
>
> We can pass variadic arguments as a array to any variadic function. But
> some our old variadic functions doesn't supports this feature.
>
> We cannot to write
>
> SELECT least(VARIADIC ARRAY[1,2,3]);
>
> Attached patch add this possibility to least, greatest functions.

Is there any particular reason you didn't just make least and greatest
actual functions?

These functions has are able to use most common type and enforce casting. Generic variadic function cannot do it.

Regards

Pavel


--
Vik Fearing                                          +33 6 46 75 15 36
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support