Skip site navigation (1) Skip section navigation (2)

Re: Function syntax ?

From: "Ruben Gouveia" <rubes7202(at)gmail(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Function syntax ?
Date: 2008-09-09 19:24:12
Message-ID: 51e507b0809091224v8a0bb6bu978bc7f7cb355174@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
It appears there is already a greatest() and least() function available...so
no need for creating this function.

On Tue, Sep 9, 2008 at 11:16 AM, Ruben Gouveia <rubes7202(at)gmail(dot)com> wrote:

> thanks pavel...that worked! I like the simplicity of your first suggestion.
>
>
> On Tue, Sep 9, 2008 at 11:05 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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(at)gmail(dot)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';
>> >
>> >
>> >
>>
>
>

In response to

pgsql-sql by date

Next:From: Emi LuDate: 2008-09-09 20:07:14
Subject: How to provide password to pg_dump command ?
Previous:From: Ruben GouveiaDate: 2008-09-09 18:16:02
Subject: Re: Function syntax ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group