Function syntax ?
От | Ruben Gouveia |
---|---|
Тема | Function syntax ? |
Дата | |
Msg-id | 51e507b0809091055l2f83eb1dmf983c1e41da46c2a@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Function syntax ?
Re: Function syntax ? |
Список | pgsql-sql |
<div dir="ltr">Does this syntax look correct? Can anyone think of a better way to write this?<br /><br />This function willaccept two timestamp parameters and determine the highest of the two?<br /><br /><span style="color: rgb(204, 0, 0);">createor replace function fcn_max_dt(p_dt timestamp without time zone,</span><br style="color: rgb(204, 0, 0);" /><spanstyle="color: rgb(204, 0, 0);"> p_dt2 timestamp without time zone)</span><brstyle="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);">returns timestamp without time zoneas $$ </span><br style="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> DECLARE</span><br style="color:rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> v_dt timestamp without time zone;</span><br style="color:rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> v_dt2 timestamp without time zone;</span><br style="color:rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> </span><br style="color: rgb(204, 0, 0);" /><spanstyle="color: rgb(204, 0, 0);"> BEGIN</span><br style="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0,0);"> v_dt := p_dt;</span><br style="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> v_dt2 := p_dt2;</span><brstyle="color: rgb(204, 0, 0);" /><br style="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> if v_dt >= v_dt2 then</span><br style="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> returnv_dt;</span><br style="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> else</span><br style="color:rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> return v_dt2;</span><br style="color: rgb(204, 0,0);" /><span style="color: rgb(204, 0, 0);"> end if;</span><br style="color: rgb(204, 0, 0);" /><span style="color:rgb(204, 0, 0);"> </span><br style="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);"> END;</span><br style="color: rgb(204, 0, 0);" /><span style="color: rgb(204, 0, 0);">$$ LANGUAGE 'plpgsql';</span><br/><br /><br /></div>
В списке pgsql-sql по дате отправления: