Hi,
I'm having a problem passing a comma-delimited list of values to a plpgsql function (stored procedure) that I've created. I'm calling the function as follows:
select * from get_total_jobs_passed_at_eol(268, date('2006-03-19'), 2, '1,2', '1');
The 4th parameter is the one that I'm having trouble with (i.e. '1,2'). The problem is that the line "user_session.user_role IN (userRole)" does not seem to be able to pick up the numbers that I'm passing in correctly (it works ok if I only pass in 1 single number - any more than that and it just returns 0). Is there a correct way of doing this? Should I be using a different datatype rather than text for the parameter? Any help would be much appreciated. Thanks. A (simplified) copy of the function is shown below:
-- Function: get_Total_Jobs_Passed_At_Eol(int8, date, int4, text, text)
-- DROP FUNCTION get_Total_Jobs_Passed_At_Eol(int8, date, int4, text, text)
CREATE OR REPLACE FUNCTION get_Total_Jobs_Passed_At_Eol(int8, date, int4, text, text)
RETURNS integer AS
$BODY$
DECLARE
userId bigint;
weekEndParam date;
numOfWeeks integer;
userRole text;
workFlowSystemId text;
totalJobsPassedAtEol integer;
BEGIN
userId := $1;
weekEndParam := $2;
numOfWeeks := $3;
userRole := $4;
workFlowSystemId := $5;
RAISE LOG '******** userRole is: %', userRole;
RAISE LOG '******** workFlowSystemId is: %', workFlowSystemId;
select into totalJobsPassedAtEol
count(distinct job_history.job_id) as totalEolPasses
from
job_history,
sm_user,
user_session
where
sm_user.sm_user_id=user_session.user_id and
sm_user.sm_user_id=userId and
job_history.session_id=user_session.session_id and
user_session.user_role IN (userRole);
RETURN totalJobsPassedAtEol;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION get_Total_Jobs_Passed_At_Eol(int8, date, int4, text, text) OWNER TO single;
I'm having a problem passing a comma-delimited list of values to a plpgsql function (stored procedure) that I've created. I'm calling the function as follows:
select * from get_total_jobs_passed_at_eol(268, date('2006-03-19'), 2, '1,2', '1');
The 4th parameter is the one that I'm having trouble with (i.e. '1,2'). The problem is that the line "user_session.user_role IN (userRole)" does not seem to be able to pick up the numbers that I'm passing in correctly (it works ok if I only pass in 1 single number - any more than that and it just returns 0). Is there a correct way of doing this? Should I be using a different datatype rather than text for the parameter? Any help would be much appreciated. Thanks. A (simplified) copy of the function is shown below:
-- Function: get_Total_Jobs_Passed_At_Eol(int8, date, int4, text, text)
-- DROP FUNCTION get_Total_Jobs_Passed_At_Eol(int8, date, int4, text, text)
CREATE OR REPLACE FUNCTION get_Total_Jobs_Passed_At_Eol(int8, date, int4, text, text)
RETURNS integer AS
$BODY$
DECLARE
userId bigint;
weekEndParam date;
numOfWeeks integer;
userRole text;
workFlowSystemId text;
totalJobsPassedAtEol integer;
BEGIN
userId := $1;
weekEndParam := $2;
numOfWeeks := $3;
userRole := $4;
workFlowSystemId := $5;
RAISE LOG '******** userRole is: %', userRole;
RAISE LOG '******** workFlowSystemId is: %', workFlowSystemId;
select into totalJobsPassedAtEol
count(distinct job_history.job_id) as totalEolPasses
from
job_history,
sm_user,
user_session
where
sm_user.sm_user_id=user_session.user_id and
sm_user.sm_user_id=userId and
job_history.session_id=user_session.session_id and
user_session.user_role IN (userRole);
RETURN totalJobsPassedAtEol;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION get_Total_Jobs_Passed_At_Eol(int8, date, int4, text, text) OWNER TO single;