getting min/max of two values

Started by rihadover 18 years ago3 messagesgeneral
Jump to latest
#1rihad
rihad@mail.ru

How can I efficiently return the minimum/maximum of two given
expressions? Like SELECT MYMIN(a+b-c,d+e*f).

Thanks.

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: rihad (#1)
Re: getting min/max of two values

2007/9/15, rihad <rihad@mail.ru>:

How can I efficiently return the minimum/maximum of two given
expressions? Like SELECT MYMIN(a+b-c,d+e*f).

Thanks.

Hello

use function GREATEST (maximim) or LEAST (minimum)

http://www.postgresql.org/docs/8.2/interactive/functions-conditional.html#AEN13148

Regards
Pavel Stehule

#3Jeff Davis
pgsql@j-davis.com
In reply to: rihad (#1)
Re: getting min/max of two values

On Sat, 2007-09-15 at 12:40 +0500, rihad wrote:

How can I efficiently return the minimum/maximum of two given
expressions? Like SELECT MYMIN(a+b-c,d+e*f).

SELECT LEAST(a+b-c,d+e*f);
SELECT GREATEST(a+b-c,d+e*f);

Regards,
Jeff Davis