Re: Why is this function wrong

Поиск
Список
Период
Сортировка
От shakahshakah@gmail.com
Тема Re: Why is this function wrong
Дата
Msg-id 1130172705.332307.296970@f14g2000cwb.googlegroups.com
обсуждение исходный текст
Ответ на Why is this function wrong  (Johan Wehtje <joweht@tpgi.com.au>)
Ответы Re: Why is this function wrong  ("shakahshakah@gmail.com" <shakahshakah@gmail.com>)
Список pgsql-general
Johan Wehtje wrote:
> This is probably obvious but I am not seeing what is going wrong with
> this function definition:
>
> CREATE OR REPLACE FUNCTION "public"."cproc_hli" (bgtemp NUMERIC,
> humidity NUMERIC, wspeed NUMERIC) RETURNS NUMERIC AS
> IF ($1 < 25)
> THEN
> SELECT (10.66 * (0.28 * $2)+(1.3 * $1) - $3)
> ELSE
> SELECT (8.62 * (0.38 * $2) + (1.55 * $1) - (0.5 * $3) + (exp(- $3 + 2.4)))
> END IF
> LANGUAGE 'plpgsql' VOLATILE RETURNS NULL ON NULL INPUT SECURITY INVOKER;
>
> ERROR:  syntax error at or near "IF" at character 119
> LINE 2: IF ($1 < 25)
>
> I have tried with dollar quoting around the function body, changing the
> maguage to sql and using CASE ... WHEN instead of IF , tried Brackets
> and no brackets around the Boolean expression.. and a number of other
> variations, as well as rereading the Documentation.
>
> I have also tried not having aliases/names for the arguments.
>
> In every case I always get the syntax error directly after "AS".
>
> Can somebody point what is probably obvious.
>
> Cheers
> Johan Wehtje

Don't you need BEGIN and END lines in there, e.g.:
CREATE OR REPLACE FUNCTION "public"."cproc_hli" (bgtemp NUMERIC,
humidity NUMERIC, wspeed NUMERIC) RETURNS NUMERIC AS
BEGIN
  IF ($1 < 25) THEN
    SELECT (10.66 * (0.28 * $2)+(1.3 * $1) - $3) ;
  ELSE
    SELECT (8.62 * (0.38 * $2) + (1.55 * $1) - (0.5 * $3) + (exp(- $3 +
2.4))) ;
  END IF ;
END ;
LANGUAGE 'plpgsql' VOLATILE RETURNS NULL ON NULL INPUT SECURITY
INVOKER;

?


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

Предыдущее
От: talenat
Дата:
Сообщение: Re: Collate problem
Следующее
От: "shakahshakah@gmail.com"
Дата:
Сообщение: Re: Why is this function wrong