Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

ERROR: cannot use RETURN NEXT in a non-SETOF function

$
0
0

I have two tables with date-columns (year, month, day and a combination of the three called "stamp") and associated values (avalue). I need my function to return the ratio between two tables (at a specified date), return a fixed value after a previously-specified limit-date, and if the date is not available in the data (but lower than the limit), it should choose the first available date following the input.

Here's the code I wrote:

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;

This keeps giving me this error:

ERROR: cannot use RETURN NEXT in a non-SETOF function


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>