Re: Function syntax ?
От | Ruben Gouveia |
---|---|
Тема | Re: Function syntax ? |
Дата | |
Msg-id | 51e507b0809091111nf208254ue796b95cddac77d5@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Function syntax ? ("Scott Marlowe" <scott.marlowe@gmail.com>) |
Ответы |
Re: Function syntax ?
|
Список | pgsql-sql |
When i tried that, i got the following error:
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 $$
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';
ERROR: syntax error at or near "v_dt" at character 1
QUERY: v_dt := $1
CONTEXT: SQL statement in PL/PgSQL function "fcn_max_dt" near line 3
********** Error **********
ERROR: syntax error at or near "v_dt"
SQL state: 42601
Context: SQL statement in PL/PgSQL function "fcn_max_dt" near line 3
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 $$
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';
ERROR: syntax error at or near "v_dt" at character 1
QUERY: v_dt := $1
CONTEXT: SQL statement in PL/PgSQL function "fcn_max_dt" near line 3
********** Error **********
ERROR: syntax error at or near "v_dt"
SQL state: 42601
Context: SQL statement in PL/PgSQL function "fcn_max_dt" near line 3
On Tue, Sep 9, 2008 at 11:07 AM, Scott Marlowe <scott.marlowe@gmail.com> wrote:
It certainly works, but there's no real need for the declarations.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';
This works just as well:BEGIN
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 $$if p_dt >= p_dt2 then
return p_dt;
else
return p_dt2;
end if;
END;
$$ LANGUAGE 'plpgsql';
В списке pgsql-sql по дате отправления: