Function returning SETOF returns nothing - Mailing list pgsql-novice

From Coby Beck
Subject Function returning SETOF returns nothing
Date
Msg-id CAO_iwXP2w3C_3La84cbXi62Eto9O64c7XesJEruGr_hTfdri0w@mail.gmail.com
Whole thread Raw
Responses Re: Function returning SETOF returns nothing  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
Hi all,

I have a monster function full of IF ELSIF branches that is supposed
to return a SETOF value, though regardless of its route through the
logic it only returns an empty row.

Fortunately, reduced to almost nothing I have the sme problem so it
will likely be a simply matter.  Function and table definition follow:

CREATE TABLE ForecastData(type TEXT, item TEXT, descr TEXT, unit TEXT,
qty FLOAT, rate FLOAT, amt FLOAT);

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';


dbtestvanek=# select * from CreateDefaultForecasts(314028);
 type | item | descr | unit | qty | rate | amt
------+------+-------+------+-----+------+-----
(0 rows)

The actual function inserts into ForecastData and then returns (SELECT
* from ForecastData where type = ''new''); or rather should do, but no
matter what it returns the same 0 rows.

What am I doing wrong, and, bonus question, where should I have found
the answer in the docs?

Thanks for your time and attention!

Coby

psql 7.4.27 on a Linux server.

pgsql-novice by date:

Previous
From: Jim Moon
Date:
Subject: Re: How to connect to remote instance?
Next
From: Tom Lane
Date:
Subject: Re: Function returning SETOF returns nothing