Amazon Redshift中的amazon-redshift – generate_series函数

栏目: 数据库 · PostgreSQL · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/22554398/generate-series-function-in-amazon-redshift

我试过以下:

SELECT * FROM generate_series(2,4);
generate_series
-----------------
           2
           3
           4
(3 rows)

SELECT * FROM generate_series(5,1,-2);                                                             
generate_series
-----------------
           5
           3
           1
(3 rows)

但是当我尝试时,

select * from generate_series('2011-12-31'::timestamp, '2012-12-31'::timestamp, '1 day');

它产生了错误.

06002

我在Redshift 1.0.757上使用PostgreSQL 8.0.2.

知道为什么会这样吗?

Postgres 8.4中添加了支持日期和时间戳的generate_series()版本.

由于Redshift基于Postgres 8.0,您需要使用不同的方式:

select timestamp '2011-12-31 00:00:00' + (i * interval '1 day')
from  generate_series(1, (date '2012-12-31' - date '2011-12-31')) i;

如果您“只”需要日期,可以缩写为:

select date '2011-12-31' + i
from  generate_series(1, (date '2012-12-31' - date '2011-12-31')) i;

翻译自:https://stackoverflow.com/questions/22554398/generate-series-function-in-amazon-redshift


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Handbook of Data Structures and Applications

Handbook of Data Structures and Applications

Dinesh P. Mehta / Chapman and Hall/CRC / 2004-10-28 / USD 135.95

In the late sixties, Donald Knuth, winner of the 1974Turing Award, published his landmark book The Art of Computer Programming: Fundamental Algorithms. This book brought to- gether a body of kno......一起来看看 《Handbook of Data Structures and Applications》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具