A summary of the RETURN SETOF variants

You learned that you can return table-like datasets from a function using one of the following:

RETURNS

RECORD structure

INSIDE function

SETOF <type>

This is obtained from the type definition

DECLARE row variable of the ROW or RECORD type

ASSIGN to row variable

RETURN NEXT var;

SETOF <table/view>

This is the same as the table or view structure

 

SETOF RECORD

Dynamic using AS (name type, …) at call site

 

SETOF RECORD

This uses the OUT and INOUT function arguments. Assigned to the OUT variables

RETURN NEXT ;

TABLE (...)

This is declared inline, in parentheses, after the TABLE keyword and is converted to the OUT variable for use in functions. It is assigned to the OUT variables from the TABLE(...) ...

Get PostgreSQL Server Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.