云服务器内容精选

  • 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
  • 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)
  • generate_series(start, stop) 描述:生成一个数值序列,从start到stop,步长默认为1。 参数类型:int、bigint、numeric 返回值类型:setof int、setof bigint、setof numeric(与参数类型相同) 示例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 SELECT * FROM generate_series(2,4); generate_series ----------------- 2 3 4 (3 rows) SELECT * FROM generate_series(4,3); generate_series ----------------- (0 rows) SELECT * FROM generate_series(1,NULL); generate_series ----------------- (0 rows)
  • 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)
  • 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
  • generate_series(start, stop) 描述:生成一个数值序列,从start到stop,步长默认为1。 参数类型:int、bigint、numeric 返回值类型:setof int、setof bigint、setof numeric(与参数类型相同) 示例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 SELECT * FROM generate_series(2,4); generate_series ----------------- 2 3 4 (3 rows) SELECT * FROM generate_series(4,3); generate_series ----------------- (0 rows) SELECT * FROM generate_series(1,NULL); generate_series ----------------- (0 rows)
  • 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)
  • generate_series(start, stop) 描述:生成一个数值序列,从start到stop,步长默认为1。 参数类型:int、bigint、numeric 返回值类型:setof int、setof bigint、setof numeric(与参数类型相同) 示例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 SELECT * FROM generate_series(2,4); generate_series ----------------- 2 3 4 (3 rows) SELECT * FROM generate_series(4,3); generate_series ----------------- (0 rows) SELECT * FROM generate_series(1,NULL); generate_series ----------------- (0 rows)
  • 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