Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在postgresql函数中动态生成表/数组_Postgresql - Fatal编程技术网

在postgresql函数中动态生成表/数组

在postgresql函数中动态生成表/数组,postgresql,Postgresql,我需要创建postgresql函数 CREATE FUNCTION date_ranges (_start date, end date) RETURNING TABLE(day_in_range date) AS... 如果我调用日期范围('2010-06-01',2010-06-05') 我应该收到 2010-06-01 2010-06-02 2010-06-03 2010-06-04 2010-06-05 有什么办法吗?如果您使用的是Postgresql 8.4: SELECT

我需要创建postgresql函数

CREATE FUNCTION date_ranges (_start date, end date) 
  RETURNING TABLE(day_in_range date) AS...
如果我调用日期范围('2010-06-01',2010-06-05') 我应该收到

2010-06-01
2010-06-02
2010-06-03
2010-06-04
2010-06-05

有什么办法吗?

如果您使用的是Postgresql 8.4:

SELECT generate_series(_start ::timestamp,_end ::timestamp,'1 day');
例如:

postgres=# SELECT generate_series('2010-06-01'::timestamp,
postgres-# '2010-06-05'::timestamp,'1 day')::date;
 generate_series
-----------------
 2010-06-01
 2010-06-02
 2010-06-03
 2010-06-04
 2010-06-05
在旧版本上:

SELECT '2010-06-01'::date + step FROM
generate_series(0,'2010-06-05'::date - '2010-06-01'::date,1) AS t(step);

看看最后一个例子:WorksPerfect-谢谢(特别是我使用的旧版本8.1)-bensiu8.1将在今年下线,开始升级到新版本。