I have written a function that takes two arguments and returns a SETOF result.
CREATE FUNCTION foo(parentId bigint, childId bigint) RETURNS SETOF bar AS ...
I would like to write two "wrappers" for this function that make it simpler to call:
CREATE FUNCTION foo_parent(parentId bigint)
RETURNS SETOF bar AS
...
BEGIN
RETURN QUERY SELECT * FROM foo(parentId, NULL);
END;
CREATE FUNCTION foo_child(childId bigint)
RETURNS SETOF bar AS
...
BEGIN
... look up parent ID ...
RETURN QUERY SELECT * FROM foo(parentId, childId);
END;
Is postgres smart enough to directly return the result of FOO()
when FOO_CHILD()
is called, or will it copy all the results from FOO()
while FOO_CHILD()
executes, then return those results?
I think I am asking if pgplsql will do tail-call optimization!
EDIT: I am using Postgres 8.2.