作者:瀚高PG实验室 (Highgo PG Lab)- 海无涯
系列生成函数(series generating functions)系列的函数是集合返回函数(possibly return more than one row)最为常见和常用的,也是postgressql的内置函数,下面介绍一下此类函数:
函数 | 参数类型 | 返回类型 | 描述 |
generate_series(start, stop) | int 或 bigint | setof int 或 setof bigint(与参数类型相同) | 生成一个数值序列,从start 到 stop,步进为1 |
generate_series(start, stop, step) | int 或 bigint | setof int 或 setof bigint(与参数类型相同) | 生成一个数值序列,从start 到 stop,步进为step |
generate_series(start, stop, step_interval) | timestamp or timestamp with time zone | timestamp 或 timestamp with time zone(same as argument type) | 生成一个数值序列,从start 到 stop,步进为step |
当 step 为正时,如果 start 大于 stop 则返回零行,反过来讲,当 step 为负时,如果 start 小于 stop 也返回零行。对于 NULL 输入也会返回零行。 step 为零是一个错误。