9.25. 集合回傳函數
本節介紹可以回傳多筆資料的函數。 此類中使用最廣泛的函數是序列生成函數,詳見 Table 9.64 和 Table 9.65。 還有其他更有用的集合回傳函數也描述在本手冊的其他地方。 請參閱第 7.2.1.4 節以了解組合多個集合傳回函數的方法。
Table 9.64. Series Generating Functions
Function
Description
generate_series
( start
integer
, stop
integer
[, step
integer
] ) → setof integer
generate_series
( start
bigint
, stop
bigint
[, step
bigint
] ) → setof bigint
generate_series
( start
numeric
, stop
numeric
[, step
numeric
] ) → setof numeric
Generates a series of values from start
to stop
, with a step size of step
. step
defaults to 1.
generate_series
( start
timestamp
, stop
timestamp
, step
interval
) → setof timestamp
generate_series
( start
timestamp with time zone
, stop
timestamp with time zone
, step
interval
) → setof timestamp with time zone
Generates a series of values from start
to stop
, with a step size of step
.
When step
is positive, zero rows are returned if start
is greater than stop
. Conversely, when step
is negative, zero rows are returned if start
is less than stop
. Zero rows are also returned if any input is NULL
. It is an error for step
to be zero. Some examples follow:
Table 9.65. Subscript Generating Functions
Function
Description
generate_subscripts
( array
anyarray
, dim
integer
) → setof integer
Generates a series comprising the valid subscripts of the dim
'th dimension of the given array.
generate_subscripts
( array
anyarray
, dim
integer
, reverse
boolean
) → setof integer
Generates a series comprising the valid subscripts of the dim
'th dimension of the given array. When reverse
is true, returns the series 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 if any input is NULL
. Some examples follow:
When a function in the FROM
clause is suffixed by WITH ORDINALITY
, a bigint
column is appended to the function's output column(s), 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 as unnest()
.
Last updated