I'm curious if there is a reason that SQL setof UDFs couldn't be inlined?
For example, given a sable setof SQL UDF like
CREATE TYPE uids AS (uid integer);
CREATE FUNCTION needs_secure(integer, integer) RETURNS SETOF uids AS $_$
SELECT uid FROM needs nsec WHERE
nsec.foo = $1 AND nsec.bar = $2
$_$ LANGUAGE SQL STABLE;
Couldn't any call to this function
SELECT * FROM needs n JOIN needs_secure( 1, 5000 ) ns ON n.uid = ns.uid;
Become
SELECT * FROM needs n JOIN (
SELECT uid FROM needs nsec WHERE
nsec.foo = 1 AND nsec.bar = 5000
) ns ON n.uid = ns.uid;
?