O'Reilly logo

PostgreSQL Server Programming by Jim Mlodgenski, Kirk Roybal, Hannu Krosing

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Summary of RETURN SETOF variants

We learned that you can return table-like data sets from a function using one of the following:

RETURNS ...

RECORD structure

INSIDE function

SETOF <type>

From type definition

DECLARE row variable of ROW or RECORD type

ASSIGN to row variable

RETURN NEXT var;

SETOF <table/view>

Same as table or view structure

 

SETOF RECORD

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

 

SETOF RECORD

Using OUT and INOUT function arguments. Assign to OUT variables.

RETURN NEXT ;

 

TABLE (...)

Declared in-line in parentheses after TABLE keyword, converted to OUT variables for use in function. Assigned to OUT variables from the TABLE(...) part of the declaration.

RETURN NEXT ;

 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required