I have a table "UserState" with following fields: id, userid, ctime, state, endtime. I have a simple query:
SELECT userid FROM "UserState" WHERE ctime>'2014-07-14'::timestamp
AND I have a plpgsql function, which must take the result of this query as an argument:
get_timeinstate(SELECT userid FROM "UserState" WHERE ctime>'2014-07-14'::timestamp);
How to create function correctly to pass a query result as parametr there? It's necessery to understand, that the function returns another SQL result and I need to use there "IN" condition:
$func$
BEGIN
RETURN QUERY
SELECT
...myanotherquery...
WHERE "UserState".userid IN (HERE I NEED TO INSERT MY QUERY RESULT)
END;
$func$