Re: Function syntax ?

Поиск
Список
Период
Сортировка
От Ruben Gouveia
Тема Re: Function syntax ?
Дата
Msg-id 51e507b0809091116tc41786codba24813a7951ee0@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Function syntax ?  ("Pavel Stehule" <pavel.stehule@gmail.com>)
Ответы Re: Function syntax ?  ("Ruben Gouveia" <rubes7202@gmail.com>)
Список pgsql-sql
thanks pavel...that worked! I like the simplicity of your first suggestion.

On Tue, Sep 9, 2008 at 11:05 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
try

create or replace function fcn_max_dt(p_dt timestamp without time zone,
                                      p_dt2 timestamp without time zone)
returns imestamp without time zone as $$
select greatest($1,$2);
$$ language sql;

or

begin
 return greatest(p_dt, p_dt2);
end;
$$ language plpgsql;

or
begin
 if p_dt > p_dt2 then
   return p_dt;
 else
   return p_dt2;
 end if;
end;
$$ language sql;

plpgsql is scripting language and almost is better minimalize number
of statements in function.

Regards
Pavel Stehule

2008/9/9 Ruben Gouveia <rubes7202@gmail.com>:
> 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';
>
>
>

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

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