Re: Largest & Smallest Functions

2018-11-08 Thread Ken Tanzer
On Thu, Nov 8, 2018 at 7:01 AM Pavel Stehule wrote: > 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/

Re: Largest & Smallest Functions

2018-11-08 Thread Pavel Stehule
čt 8. 11. 2018 v 7:02 odesílatel Ken Tanzer napsal: > > > On Wed, Nov 7, 2018 at 9:48 PM Pavel Stehule > wrote: > >> >> You can pass variadic arguments as a array >> >> postgres=# \sf smallest >> CREATE OR REPLACE FUNCTION public.smallest(VARIADIC anyarray) >> RETURNS anyelement >> LANGUAGE sq

Re: Largest & Smallest Functions

2018-11-07 Thread Pavel Stehule
čt 8. 11. 2018 v 7:34 odesílatel Andrew Gierth napsal: > > "Pavel" == Pavel Stehule writes: > > Pavel> The variadic parameters should not be a arrays - can be of "any" > Pavel> type. But this functionality is available only for C language > Pavel> functions. > > You mean (VARIADIC "any")?

Re: Largest & Smallest Functions

2018-11-07 Thread Andrew Gierth
> "Pavel" == Pavel Stehule writes: Pavel> The variadic parameters should not be a arrays - can be of "any" Pavel> type. But this functionality is available only for C language Pavel> functions. You mean (VARIADIC "any")? - that is not actually restricted to C language functions, any pl/*

Re: Largest & Smallest Functions

2018-11-07 Thread Ken Tanzer
On Wed, Nov 7, 2018 at 10:10 PM Andrew Gierth wrote: > > But you don't need to create more functions, because you can do this: > > select largest(variadic array[1,2,3]); > largest > - >3 > > > As already pointed out, greatest() and least() exist (though they were > added before

Re: Largest & Smallest Functions

2018-11-07 Thread Pavel Stehule
čt 8. 11. 2018 v 7:11 odesílatel Andrew Gierth napsal: > > "Ken" == Ken Tanzer writes: > > Ken> Hi. Building on the [type]_larger and _smaller functions (and > Ken> lifting from the documentation), I put together a couple of > Ken> functions that will take any number of arguments: > > Ke

Re: Largest & Smallest Functions

2018-11-07 Thread Andrew Gierth
> "Ken" == Ken Tanzer writes: Ken> Hi. Building on the [type]_larger and _smaller functions (and Ken> lifting from the documentation), I put together a couple of Ken> functions that will take any number of arguments: Ken> CREATE FUNCTION largest(VARIADIC anyarray) RETURNS anyelement AS

Re: Largest & Smallest Functions

2018-11-07 Thread Pavel Stehule
čt 8. 11. 2018 v 7:02 odesílatel Ken Tanzer napsal: > > > On Wed, Nov 7, 2018 at 9:48 PM Pavel Stehule > wrote: > >> >> You can pass variadic arguments as a array >> >> postgres=# \sf smallest >> CREATE OR REPLACE FUNCTION public.smallest(VARIADIC anyarray) >> RETURNS anyelement >> LANGUAGE sq

Re: Largest & Smallest Functions

2018-11-07 Thread Ken Tanzer
On Wed, Nov 7, 2018 at 9:48 PM Pavel Stehule 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_s

Re: Largest & Smallest Functions

2018-11-07 Thread Pavel Stehule
st 7. 11. 2018 v 22:38 odesílatel Ken Tanzer napsal: > Hi. Building on the [type]_larger and _smaller functions (and lifting > from the documentation), I put together a couple of functions that will > take any number of arguments: > > CREATE FUNCTION largest(VARIADIC anyarray) RETURNS anyelement

Re: Largest & Smallest Functions

2018-11-07 Thread Ken Tanzer
On Wed, Nov 7, 2018 at 2:46 PM Ondřej Bouda wrote: > Hi, > > > 2) Is there any particular reason functions like that aren't built > > into Postgres? They seem like they would be useful. (Or maybe I > > missed them?) > > LEAST() and GREATEST() expressions do the same thing as yours smallest()

Re: Largest & Smallest Functions

2018-11-07 Thread Ondřej Bouda
Hi, > 2) Is there any particular reason functions like that aren't built > into Postgres? They seem like they would be useful. (Or maybe I > missed them?) LEAST() and GREATEST() expressions do the same thing as yours smallest() and largest(). See https://www.postgresql.org/docs/current/funct

Largest & Smallest Functions

2018-11-07 Thread Ken Tanzer
Hi. Building on the [type]_larger and _smaller functions (and lifting from the documentation), I put together a couple of functions that will take any number of arguments: CREATE FUNCTION largest(VARIADIC anyarray) RETURNS anyelement AS $$ SELECT max($1[i]) FROM generate_subscripts($1, 1) g(i); $