Re: minimum function - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: minimum function
Date
Msg-id 467D4BD8.4040804@iol.ie
Whole thread Raw
In response to minimum function  (Gunther Mayer <gunther.mayer@googlemail.com>)
Responses Re: minimum function  (PFC <lists@peufeu.com>)
List pgsql-general
On 23/06/2007 17:17, Gunther Mayer wrote:

> Any way I can achieve that on one line? I.e. I want it simpler than
>
> IF arg1 < arg2 THEN
>    RETURN arg1;
> ELSE
>    RETURN arg2;
> END IF;

That looks pretty simple already, but why not enclose it in a pl/pgsql
function - something like:

create function minimum(a1 integer, a2 integer) returns integer as
$$
begin
   if a1 < a2 then
     return a1;
   else
     return a2;
   end if;
end;
$$
language plpgsql;

- and then you can call it in one line:

select minimum(5, 4);


Ray.


---------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
---------------------------------------------------------------

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: B-tree fan-out
Next
From: PFC
Date:
Subject: Re: minimum function