Re: Function syntax ?

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: Function syntax ?
Дата
Msg-id dcc563d10809091107m11202269p68e6fbf3be197dcb@mail.gmail.com
обсуждение исходный текст
Ответ на Function syntax ?  ("Ruben Gouveia" <rubes7202@gmail.com>)
Ответы Re: Function syntax ?  ("Ruben Gouveia" <rubes7202@gmail.com>)
Re: Function syntax ?  (Richard Huxton <dev@archonet.com>)
Список pgsql-sql
On Tue, Sep 9, 2008 at 11:55 AM, Ruben Gouveia <rubes7202@gmail.com> wrote:
> Does this syntax look correct? Can anyone think of a better way to write
> this?
>
> This function will accept two timestamp parameters and determine the highest
> of the two?
>
> create or replace function fcn_max_dt(p_dt timestamp without time zone,
>                                       p_dt2 timestamp without time zone)
> returns timestamp without time zone as $$
>   DECLARE
>       v_dt timestamp without time zone;
>       v_dt2 timestamp without time zone;
>
>   BEGIN
>     v_dt := p_dt;
>     v_dt2 := p_dt2;
>
>     if v_dt >= v_dt2 then
>     return v_dt;
>     else
>     return v_dt2;
>     end if;
>
>   END;
> $$ LANGUAGE 'plpgsql';

It certainly works, but there's no real need for the declarations.
This works just as well:

create or replace function fcn_max_dt(p_dt timestamp without time zone,                                     p_dt2
timestampwithout time zone)
 
returns timestamp without time zone as $$
   BEGIN   if p_dt >= p_dt2 then   return p_dt;   else   return p_dt2;   end if;
 END;
$$ LANGUAGE 'plpgsql';


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

Предыдущее
От: "Ruben Gouveia"
Дата:
Сообщение: Function syntax ?
Следующее
От: "Ruben Gouveia"
Дата:
Сообщение: Re: Function syntax ?