From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Largest & Smallest Functions |
Date: | 2018-11-08 15:00:53 |
Message-ID: | CAFj8pRDSubnVQW5mOeL9abMvEM-M=junLpfRUU+dXV1G3CL=kQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
čt 8. 11. 2018 v 7:02 odesílatel Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com> napsal:
>
>
> On Wed, Nov 7, 2018 at 9:48 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> 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.
>
I sent a patch to pgsql-hackares that allows VARIADIC argument for
LEAST/GREATEST
Regards
Pavel
>
> Thanks!
>
> Ken
>
>
> --
> AGENCY Software
> A Free Software data system
> By and for non-profits
> *http://agency-software.org/ <http://agency-software.org/>*
> *https://demo.agency-software.org/client
> <https://demo.agency-software.org/client>*
> ken(dot)tanzer(at)agency-software(dot)org
> (253) 245-3801
>
> Subscribe to the mailing list
> <agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
> learn more about AGENCY or
> follow the discussion.
>
From | Date | Subject | |
---|---|---|---|
Next Message | Ken Tanzer | 2018-11-08 16:53:19 | Re: Largest & Smallest Functions |
Previous Message | Amine Tengilimoglu | 2018-11-08 13:08:09 | Upgrade Standby |