Postgresql创建函数错误

时间:2017-11-13 12:08:05

标签: sql postgresql plpgsql

我在以下功能中做错了什么?

CREATE OR REPLACE FUNCTION extended_sales(area_type varchar, area_code varchar, dpci varchar) RETURNS TABLE(task_id bigint, location_id int)as

$BODY$

BEGIN 
    IF area_type = 1 THEN
        RETURN QUERY select T.task_id, T.location_id from store_price.task T where T.task_payload->>'str_area_type_i'='3';
    ELSE IF area_type = 2 THEN
        RETURN QUERY select T.task_id, T.location_id from store_price.task T where T.due_date < '2017-10-06';
    ELSE
        RETURN QUERY select T.task_id, T.location_id from store_price.task T where task_payload->>'str_area_type_i'='1' and task_payload->>'str_area_c'='7'  and due_date < '2016-11-07';
    END IF;


END

$BODY$ language plpgsql;

当我运行上述功能时,它会出现以下错误

ERROR:  syntax error at end of input
LINE 17: $BODY$ language plpgsql;

感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:5)

您有两个IF语句和一个END IF。如果您想要一个IF statement.

,请使用ELSIF
InsertReq="Insert into "+ tablename + " select * from external '"+ filepath + "' using (maxerrors 0, delimiter ',' unase 2000 encoding 'internal' remotesource 'jdbc' escapechar '\' )";
Jdbctemplate.execute(InsertReq);