I've a table with VARCHAR
as PRIMARY_KEY
, so my IDs are randomly generated and looks like WUoN5VemT
or MQvOQidTi
. I just want write a function which expects an array as input and returns all elements which are contained in the array. I think the following semi-code will show better it a way better:
CREATE OR REPLACE FUNCTION public."getInfo" (
"myIDs" varchar []
)
RETURNS varchar AS
$body$
BEGIN
SELECT * FROM "myTable" WHERE "id" IN($1) ORDER BY "idDate" DESC;
-- RETURN etc....
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;
But the problem is the array can contain 50 or more entries (100 are also possible), so I need to do this as fast as possible. The next problem is, the code above doesn't work. I often found the solution for multiple values using the IN
-keyword, but is there any way to combine arrays and IN
-clause?
Is there any chance to realize this using a function?