数据仓库服务 GAUSSDB(DWS)-序列号生成函数:generate_series(start, stop, step)

时间:2024-12-06 15:12:47

generate_series(start, stop, step)

描述:生成一个数值序列,从start到stop,步长为step。

参数类型:int、bigint、numeric

返回值类型:setof int、setof bigint、setof numeric(与参数类型相同)

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
SELECT * FROM generate_series(5,1,-2);
 generate_series
-----------------
               5
               3
               1
(3 rows)

SELECT * FROM generate_series(4,6,-5);
 generate_series
-----------------
(0 rows)

SELECT * FROM generate_series(4,3,0);
ERROR:  step size cannot equal zero
support.huaweicloud.com/sqlreference-910-dws/dws_06_0336.html