From: | PFC <lists(at)peufeu(dot)com> |
---|---|
To: | rod(at)iol(dot)ie, "Gunther Mayer" <gunther(dot)mayer(at)googlemail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: minimum function |
Date: | 2007-06-23 16:48:35 |
Message-ID: | op.tudvm9d9cigqcu@apollo13 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Check out greatest() and least()... (I think ;)
On Sat, 23 Jun 2007 18:35:36 +0200, Raymond O'Donnell <rod(at)iol(dot)ie> wrote:
> 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(at)iol(dot)ie
> ---------------------------------------------------------------
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org/
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2007-06-23 16:49:19 | Re: minimum function |
Previous Message | Raymond O'Donnell | 2007-06-23 16:35:36 | Re: minimum function |