Amazon Redshift中的amazon-redshift – generate_series函数

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

Introduction to Computer Science Using Python

Introduction to Computer Science Using Python

Dierbach, Charles / 2012-12 / $ 133.62

Introduction to Computer Science Using Python: A Computational Problem-Solving Focus introduces students to programming and computational problem-solving via a back-to-basics, step-by-step, objects-la......一起来看看 《Introduction to Computer Science Using Python》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

MD5 加密
MD5 加密

MD5 加密工具

html转js在线工具
html转js在线工具

html转js在线工具