Re: Largest & Smallest Functions

From: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
To: obouda(at)email(dot)cz
Cc: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Largest & Smallest Functions
Date: 2018-11-07 23:19:12
Message-ID: CAD3a31WXBhO-noONAeG=W5yfi+dFPCiMmO704nHeowFZgFP8oQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Nov 7, 2018 at 2:46 PM Ondřej Bouda <obouda(at)email(dot)cz> 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()
> and largest(). See
> https://www.postgresql.org/docs/current/functions-conditional.html
>
>
Ah, thanks very much! I missed those because I didn't see them as
functions, and didn't think about expressions.

But then going back to my Q3, what is the point of the separate
date_larger,int2smaller, etc. functions? Are they faster than
least/greatest because they are specific to a particular data type?

> Now to be a little more serious, if you want a single function to both
> support variadic number of arguments AND all of them in a single array,
> how could the function decide whether smallest(ARRAY[1,2,3]) shall
> return 1 or ARRAY[1,2,3] (which is the smallest out of all arguments)?
>

Personally I don't have any use cases where I'd be comparing arrays, and so
would be happy to have a single array be treated as a list of elements.
But I definitely see your point in more general terms!

Thanks again,
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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul Schaap 2018-11-08 02:28:05 Postgres 11.0 Partitioned Table Query Performance
Previous Message Ondřej Bouda 2018-11-07 22:46:46 Re: Largest & Smallest Functions