Re: Function returning SETOF returns nothing - Mailing list pgsql-novice

From Tom Lane
Subject Re: Function returning SETOF returns nothing
Date
Msg-id 24436.1333547608@sss.pgh.pa.us
Whole thread Raw
In response to Function returning SETOF returns nothing  (Coby Beck <coby101@gmail.com>)
Responses Re: Function returning SETOF returns nothing  (Coby Beck <coby101@gmail.com>)
List pgsql-novice
Coby Beck <coby101@gmail.com> writes:
> CREATE OR REPLACE FUNCTION CreateDefaultForecasts(INTEGER) RETURNS
> SETOF ForecastData AS '
>     BEGIN
>     RETURN (SELECT ''old'' as type, ''item'' as item, ''descr'' as
> descr, ''unit'' as unit, 0 as qty, 0 rate, 0 as amt);
>     END;
> ' LANGUAGE 'plpgsql';

Um ... what Postgres version are you using?  Everything since about 8.0
will tell you pretty clearly what is wrong with this function:

ERROR:  RETURN cannot have a parameter in function returning set
LINE 4:     RETURN (SELECT ''old'' as type, ''item'' as item, ''desc...
                   ^
HINT:  Use RETURN NEXT or RETURN QUERY.

In a SETOF function, plain RETURN is just a flow-of-control command,
and you need to use RETURN NEXT (or possibly RETURN QUERY) to feed
actual rows back to the output.

If you really are using 7.x, you need to update.  Soon, before it
eats your data.

            regards, tom lane

pgsql-novice by date:

Previous
From: Coby Beck
Date:
Subject: Function returning SETOF returns nothing
Next
From: Steve Horn
Date:
Subject: Transactions within Function