pl_pgSQL array parameter and order of results returned

Started by Assad Jarrahianover 20 years ago1 messagesgeneral
Jump to latest
#1Assad Jarrahian
jarraa@gmail.com

Hi All,
I have a quick question. So I pass an array (int containing primary
keys) to a pgSQL function and I want the results to be in the exact
same order as the ints in the array. Is there a way to do this ?

currently my code looks like this

CREATE OR REPLACE FUNCTION getlms(_int4)
RETURNS SETOF lms AS
$BODY$
DECLARE
myrec record;
requestIds ALIAS for $1;
BEGIN
FOR myrec IN SELECT * FROM lms
WHERE LMID = ANY (requestIDs) LOOP RETURN NEXT myrec; END LOOP;
RETURN; END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

It returns the rows in the order in which it finds them (smallest to
biggest primary key)? Any help, suggestions would be appreciated. Much
thanks in advance.
-assad