Thread: Possible to inline setof SQL UDFs?

Possible to inline setof SQL UDFs?

From
richard@bowmansystems.com
Date:
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 WHEREnsec.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 WHEREnsec.foo = 1 AND nsec.bar = 5000
) ns ON n.uid = ns.uid;

?


Re: Possible to inline setof SQL UDFs?

From
Tom Lane
Date:
richard@bowmansystems.com writes:
> I'm curious if there is a reason that SQL setof UDFs couldn't be inlined?  

Lack of round tuits, I think.

I seem to recall having looked at it awhile ago and concluded that it
wasn't quite trivial, but I forget why.
        regards, tom lane