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 など) に取り込み、その結果をデータベースに挿入することですが、それはハックのようです。
redshift を使用したことがない方のために説明すると、これは postgresql を大幅に変更した変種であり、独自の特異性がたくさんあります。以下のクエリは完全に有効で、正常に実行されます。
create table test diststyle all as (select 1 as a, 2 as b);
select * from test
収量:
a b
1 2
この問題は、redshift でのリーダーノードのみの機能と計算ノード機能の違いに起因します。クエリのバグによるものではないと確信しています。