0

在 Amazon Redshift 中,generate_series()领导节点似乎支持,但计算节点不支持。有没有办法使用 generate_series 在领导节点上创建表,然后将其推送到计算节点?

此查询运行良好,在领导节点上运行:

with
    date_table as (select now()::date - generate_series(0, 7 * 10) as date),
    hour_table as (select generate_series(0, 24) as hour),
    time_table as (
      select 
        date_table.date::date as date,
        extract(year from date_table.date) as year,
        extract(month from date_table.date) as month,
        extract(day from date_table.date) as day,
        hour_table.hour
    from date_table CROSS JOIN hour_table
)
SELECT * 
from time_table

但是,此查询失败:

create table test
diststyle all
as (
  with
      date_table as (select now()::date - generate_series(0, 7 * 10) as date),
      hour_table as (select generate_series(0, 24) as hour),
      time_table as (
        select 
          date_table.date::date as date,
          extract(year from date_table.date) as year,
          extract(month from date_table.date) as month,
          extract(day from date_table.date) as day,
          hour_table.hour
    from date_table CROSS JOIN hour_table
)
  SELECT * 
  from time_table 
);

我现在能想到的唯一解决方案是将查询结果拉入另一个程序(例如python),然后将结果插入数据库,但这似乎很hackish。

对于那些从未使用过 redshift 的人来说,它是 postgresql 的一个经过大量修改的变体,并且有很多自己的特质。以下查询完全有效,运行良好:

create table test diststyle all as (select 1 as a, 2 as b);
select * from test

产量:

a   b
1   2

问题源于仅领导节点功能和红移计算节点功能之间的差异。我很确定这不是由于我的查询中的错误。

4

1 回答 1

1

我还没有找到一种方法来使用仅领导节点的功能来创建表。没有(AFAICT)任何魔术语法可用于使它们将输出加载回表。

我最终使用数字表来实现类似的结果。通过运行长度压缩,即使是一个巨大的数字表在 Redshift 集群上占用的空间也很少。

于 2014-11-03T21:02:05.800 回答