On Wed, Nov 7, 2018 at 9:48 PM Pavel Stehule <pavel.stehule@gmail.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 IMMUTABLEAS $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.
You can pass variadic arguments as a array postgres=# \sf smallest CREATE OR REPLACE FUNCTION public.smallest(VARIADIC anyarray) RETURNS anyelement LANGUAGE sql IMMUTABLEAS $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)
Thanks!Ken-- AGENCY Software A Free Software data systemBy and for non-profitshttp://agency-software.org/https://demo.agency-software.org/clientken.tanzer@agency-software.org(253) 245-3801Subscribe to the mailing list tolearn more about AGENCY orfollow the discussion.
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных