Setof
When our plpgsql function returns a setof rows, we must follow a different procedure:
- the items that are returned by the function are specified by the
RETURN NEXTorRETURN QUERYcommands. - at the end, a final
RETURNcommand with no argument, to indicate the function has finished execution.
RETURN NEXT and RETURN QUERY do not actually cause execution to return from the function call. Instead, they simply append zero or more rows to the function's result set.
- As successive RETURN NEXT or RETURN QUERY commands are executed, the result set is appended to further. The final
RETURNcommand causes control to exit the function, leaving us with the dataset that has been constructed up until that point- note: naturally, we can omit the final
RETURNif we are at the last line anyway
- note: naturally, we can omit the final