Possible to inline setof SQL UDFs?

Started by Richard Rowellalmost 19 years ago2 messageshackers
Jump to latest
#1Richard Rowell
richard@bowmansystems.com

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;

?

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Richard Rowell (#1)
Re: Possible to inline setof SQL UDFs?

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