9.24. 集合回傳函式
This section describes functions that possibly return more than one row. The most widely used functions in this class are series generating functions, as detailed inTable 9.58andTable 9.59. Other, more specialized set-returning functions are described elsewhere in this manual. SeeSection 7.2.1.4for ways to combine multiple set-returning functions.
Table 9.58. Series Generating Functions
Function
Argument Type
Return Type
Description
generate_series(start
,stop
)
int
,bigint
ornumeric
setof int
,setof bigint
, orsetof numeric
(same as argument type)
Generate a series of values, fromstart
_tostop
_with a step size of one
generate_series(start
,stop
,step
)
int
,bigint
ornumeric
setof int
,setof bigint
orsetof numeric
(same as argument type)
Generate a series of values, fromstart
_tostop
with a step size ofstep
_
generate_series(start
,stop
,stepinterval
)
timestamp
ortimestamp with time zone
setof timestamp
orsetof timestamp with time zone
(same as argument type)
Generate a series of values, fromstart
_tostop
with a step size ofstep
_
Whenstep
_is positive, zero rows are returned ifstart
is greater thanstop
. Conversely, whenstep
is negative, zero rows are returned ifstart
is less thanstop
. Zero rows are also returned forNULL
inputs. It is an error forstep
_to be zero. Some examples follow:
Table 9.59. Subscript Generating Functions
Function
Return Type
Description
generate_subscripts(array anyarray
,dim int
)
setof int
Generate a series comprising the given array's subscripts.
generate_subscripts(array anyarray
,dim int
,reverse boolean
)
setof int
Generate a series comprising the given array's subscripts. When_reverse
_is true, the series is returned in reverse order.
generate_subscripts
is a convenience function that generates the set of valid subscripts for the specified dimension of the given array. Zero rows are returned for arrays that do not have the requested dimension, or for NULL arrays (but valid subscripts are returned for NULL array elements). Some examples follow:
When a function in theFROM
clause is suffixed byWITH ORDINALITY
, abigint
column is appended to the output which starts from 1 and increments by 1 for each row of the function's output. This is most useful in the case of set returning functions such asunnest()
.
Last updated