I am new to postgres and getting an error that I can't seem to find on Stackoverflow (?). I am trying to write a function that returns true when a person is qualified for a job and false if they are not. This raises "ERROR: ROWS is not applicable when function does not return a set." Found some stuff in spanish--but nothing on SO. Can someone explain this one?
CREATE OR REPLACE FUNCTION "isPersonQualifiedForJob"(pid integer, jid integer)
RETURNS bit AS
'
IF
(SELECT count(*) FROM "getSkillsForJob"("jid") "j" WHERE
NOT EXISTS (
SELECT 1 FROM "getSkillsForPerson"("pid") "p" WHERE "j"."SkillID"="p"."SkillID"
)
)> 0
THEN
return 0;
ELSE
return 1;
END IF;
'
LANGUAGE sql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION "isPersonQualifiedForJob"(integer)
OWNER TO postgres;
In this line:
ROWS 1000;
you are telling the planner you expect about 1,000 rows to return from the function but it is declared to return just a single value, a bit:
RETURNS bit AS
The message is quite clear, and the docs :
ROWS result_rows
A positive number giving the estimated number of rows that the planner should expect the function to return. This is only allowed when the function is declared to return a set. The default assumption is 1000 rows.
Your function is not returning a set of rows, but a single boolean, hence I don't know why you are adding that line ROWS 1000
(copy-paste from other function?). Just remove it and you should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With