Re: Largest & Smallest Functions

Поиск
Список
Период
Сортировка
От Ken Tanzer
Тема Re: Largest & Smallest Functions
Дата
Msg-id CAD3a31WXBhO-noONAeG=W5yfi+dFPCiMmO704nHeowFZgFP8oQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Largest & Smallest Functions  (Ondřej Bouda <obouda@email.cz>)
Список pgsql-general
On Wed, Nov 7, 2018 at 2:46 PM Ondřej Bouda <obouda@email.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
(253) 245-3801

learn more about AGENCY or
follow the discussion.

В списке pgsql-general по дате отправления:

Предыдущее
От: Ondřej Bouda
Дата:
Сообщение: Re: Largest & Smallest Functions
Следующее
От: Paul Schaap
Дата:
Сообщение: Postgres 11.0 Partitioned Table Query Performance