Search Postgresql Archives

Re: Largest & Smallest Functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





čt 8. 11. 2018 v 7:02 odesílatel Ken Tanzer <ken.tanzer@xxxxxxxxx> napsal:


On Wed, Nov 7, 2018 at 9:48 PM Pavel Stehule <pavel.stehule@xxxxxxxxx> wrote:

You can pass variadic arguments as a array

postgres=# \sf smallest
CREATE OR REPLACE FUNCTION public.smallest(VARIADIC anyarray)
 RETURNS anyelement
 LANGUAGE sql
 IMMUTABLE
AS $function$
    SELECT min($1[i]) FROM generate_subscripts($1, 1) g(i);
$function$

postgres=# select smallest(VARIADIC ARRAY[1,2,3]);
┌──────────┐
│ smallest │
╞══════════╡
│        1 │
└──────────┘
(1 row)


That's very helpful and good to know. It's too bad that doesn't work with LEAST/GREATEST, which would eliminate the need for extra functions.

These functions are differently implemented - and they are older than support of variadic functions.But implementation of passing a array should be easy.

Pavel


Thanks!

Ken


--
AGENCY Software  
A Free Software data system
By and for non-profits
(253) 245-3801

learn more about AGENCY or
follow the discussion.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux