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

时间:2024-10-16 16:27:29

generate_series(start, stop, step interval)

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

参数类型:timestamp或timestamp with time zone

返回值类型:setof timestamp或setof timestamp with time zone(与参数类型相同)

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
--这个示例应用于date-plus-integer操作符。
SELECT current_date + s.a AS dates FROM generate_series(0,14,7) AS s(a);
   dates
------------
 2017-06-02
 2017-06-09
 2017-06-16
(3 rows)

SELECT * FROM generate_series('2008-03-01 00:00'::timestamp, '2008-03-04 12:00', '10 hours');
   generate_series   
---------------------
 2008-03-01 00:00:00
 2008-03-01 10:00:00
 2008-03-01 20:00:00
 2008-03-02 06:00:00
 2008-03-02 16:00:00
 2008-03-03 02:00:00
 2008-03-03 12:00:00
 2008-03-03 22:00:00
 2008-03-04 08:00:00
(9 rows)
support.huaweicloud.com/sqlreference-dws/dws_06_0336.html