【问题标题】:Trying to create a date sequence yyyymmdd尝试创建日期序列 yyyymmdd
【发布时间】:2019-09-13 04:14:30
【问题描述】:

我正在尝试以以下格式创建日期范围序列 yyyymmdd

insert into dim_SH (date_key)
SELECT to_char(('2012-01-01'::date + x)::date,'yyyymmdd') 
FROM generate_series(1, 365*15, 1) x;

Amazon 无效操作:Redshift 表不支持指定的类型或函数(每条 INFO 消息一个)。 1 条语句失败。

【问题讨论】:

标签: sql amazon-redshift


【解决方案1】:

GENERATE_SERIES 确实 据说 Redshift 不支持(这里Redshift documentation 表示不支持),因此每当您需要生成行时,您必须在飞(如下所示):

WITH ten as (
  select 1 union all
  select 1 union all
  select 1 union all
  select 1 union all
  select 1 union all
  select 1 union all
  select 1 union all
  select 1 union all
  select 1 union all
  select 1
), ten_k as (
  select row_number() over () as x
  from ten a cross join
     ten b cross join
     ten c cross join
     ten d
  )
SELECT to_char(('2012-01-01'::date + x)::date,'yyyymmdd')
FROM ten_k limit 365*15;

或者,您可以从某处选择行:

SELECT x FROM (SELECT row_number() over () as x FROM arbitrary_table limit 10000) as ten_k

GENERATE_SERIES真的不支持吗?

看到您发布的查询我震惊

SELECT to_char(('2012-01-01'::date + x)::date,'yyyymmdd')
FROM generate_series(1, 365*15, 1) x;

在针对我们的 Redshift(版本 1.0.7078)运行时确实有效。 Release notes 没有提及该区域的任何功能 [:puzzled:]。

编辑: 显然as of this questiongenerate_series 仅在领导节点上工作,但每当您的查询需要到达计算节点时就会失败。

因此,不完全支持此功能认为它不支持

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2022-11-23
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多