PostgreSQL code problem
-
why this code returns all rows although I specified the condition? how to correct?
CREATE OR REPLACE FUNCTION fn_get_resume_details2(resume_id integer)
RETURNS SETOF record AS$$select resume_id, resume_title, objective_title, objective_text, summary_title, summary_text from resume_details where resume_id = resume_id;
$$LANGUAGE sql;
</pre> -
why this code returns all rows although I specified the condition? how to correct?
CREATE OR REPLACE FUNCTION fn_get_resume_details2(resume_id integer)
RETURNS SETOF record AS$$select resume_id, resume_title, objective_title, objective_text, summary_title, summary_text from resume_details where resume_id = resume_id;
$$LANGUAGE sql;
</pre>In your where clause, resume_id = resume_id, that is the same as saying where 1 = 1. It will be true for all rows. I'd recommend changing the name of your parameter to be different from the column name.
CREATE OR REPLACE FUNCTION fn_get_resume_details2(in_resume_id integer)
RETURNS SETOF record AS
$$select resume_id
,resume_title
,objective_title
,objective_text
,summary_title
,summary_text
from resume_details
where resume_id = in_resume_id;
$$LANGUAGE sql;:)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]