Re: LEAST and GREATEST functions?

Поиск
Список
Период
Сортировка
Искать
От
Ang Chin Han
Тема
Re: LEAST and GREATEST functions?
Дата
Msg-id
3F025942.6000507@bytecraft.com.my
Ответ на
Список
Дерево обсуждения
LEAST and GREATEST functions? Stefan Bill <sjb26@yahoo.com>
Re: LEAST and GREATEST functions? Josh Berkus <josh@agliodbs.com>
Re: LEAST and GREATEST functions? Stefan Bill <sjb26@yahoo.com>
Re: LEAST and GREATEST functions? Greg Stark <gsstark@mit.edu>
Re: LEAST and GREATEST functions? Bruno Wolff III <bruno@wolff.to>
Re: LEAST and GREATEST functions? Joe Conway <mail@joeconway.com>
Re: LEAST and GREATEST functions? Josh Berkus <josh@agliodbs.com>
Re: LEAST and GREATEST functions? Joe Conway <mail@joeconway.com>
Re: LEAST and GREATEST functions? Joe Conway <mail@joeconway.com>
Re: LEAST and GREATEST functions? Ang Chin Han <angch@bytecraft.com.my>
Re: LEAST and GREATEST functions? Tom Lane <tgl@sss.pgh.pa.us>
Re: LEAST and GREATEST functions? Ang Chin Han <angch@bytecraft.com.my>
Re: LEAST and GREATEST functions? Tom Lane <tgl@sss.pgh.pa.us>
Re: LEAST and GREATEST functions? Ang Chin Han <angch@bytecraft.com.my>
Greg Stark wrote:

> MAX and MIN are single-parameter aggregate functions. LEAST and GREATEST are
> two-parameter (though in postgres they could be defined for 3 and more
> parameters) scalar functions.

If LEAST and GREATEST can accept any number of parameters, wouldn't it 
make sense to code it like the way COALESCE works, rather than defining 
a function for it? This way we don't need define all the various 
functions with different types.

e.g.

SELECT greatest(a, b, c) FROM bar;

becomes

SELECT greatest(a, greatest(b, c)) from bar;

becomes

SELECT  CASE WHEN b < c    THEN      CASE WHEN c < a        THEN a        ELSE c      END    ELSE      CASE WHEN b < a        THEN a        ELSE b      END  END
FROM bar;

From the docs:

COALESCE and NULLIF are just shorthand for CASE expressions. They are 
actually converted into CASE expressions at a very early stage of 
processing, and subsequent processing thinks it is dealing with CASE. 
Thus an incorrect COALESCE or NULLIF usage may draw an error message 
that refers to CASE.

-- 
Linux homer 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 
GNU/Linux 11:30am  up 188 days,  2:35,  5 users,  load average: 5.19, 5.08, 5.02
В списке pgsql-sql по дате отправления
От: Jonathan Man
Дата:
Сообщение: Timeout for lock table
От: Rudi Starcevic
Дата:
Сообщение: Break referential integrity.
FAQ