PL/pgSQL Table-Returning Functions — RETURNS TABLE, SETOF and When a View Is Better
A view is the most elegant way to encapsulate a recurring query — right up to the moment the query needs an argument from outside. A view has no parameters. As soon as a value belongs in the WHERE that the caller supplies, the table-valued function is the tool of choice: a function that returns an entire result set … Read more