在 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
问题源于仅领导节点功能和红移计算节点功能之间的差异。我很确定这不是由于我的查询中的错误。