我有两个带有日期列的表(年、月、日以及称为“邮票”的三者的组合)和相关值(avalue)。我需要我的函数返回两个表之间的比率(在指定日期),在先前指定的限制日期之后返回一个固定值,如果数据中没有日期(但低于限制),它应选择输入后的第一个可用日期。
这是我写的代码:
CREATE OR REPLACE FUNCTION myfunction(theyear int, themonth int, theday int) RETURNS real AS '
DECLARE
foo tablenamea%rowtype;
BEGIN
IF ((theyear >= 2000) AND (themonth >= 6)) OR (theyear > 2000) THEN
RETURN 0.1;
ELSE
FOR foo IN SELECT (a.avalue/b.avalue) FROM tablenamea AS a, tablenameb AS b
WHERE a.stamp = b.stamp AND a.year = theyear AND a.month = themonth AND a.day >= theday ORDER BY a.year, a.month, a.day
LOOP
RETURN NEXT foo;
END LOOP;
RETURN;
END IF;
END;
' LANGUAGE plpgsql;
这一直给我这个错误:
cannot use RETURN NEXT in a non-SETOF function