Postgresql 使用generate_series创建表
在Amazon Redshift中,Postgresql 使用generate_series创建表,postgresql,amazon-redshift,generate-series,Postgresql,Amazon Redshift,Generate Series,在Amazon Redshift中,generate_series()似乎在leader节点上受支持,但在compute节点上不受支持。有没有办法使用generate_series在leader节点上创建一个表,然后将其推送到compute节点 此查询运行良好,在“引线”节点上运行: with date_table as (select now()::date - generate_series(0, 7 * 10) as date), hour_table as (select
generate_series()
似乎在leader节点上受支持,但在compute节点上不受支持。有没有办法使用generate_series在leader节点上创建一个表,然后将其推送到compute节点
此查询运行良好,在“引线”节点上运行:
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)中,然后将结果插入数据库,但这似乎有点老套
对于那些从未使用过红移的人来说,它是postgresql的一个经过大量修改的变体,并且有很多自己的特性。以下查询完全有效,运行正常:
create table test diststyle all as (select 1 as a, 2 as b);
select * from test
收益率:
a b
1 2
这个问题源于redshift上leadernode only函数和compute node函数之间的差异。我很确定这不是因为我的查询中有错误。我还没有找到一种方法来使用leader node only函数来创建表。没有(AFAICT)任何神奇的语法可以让它们将输出加载回表中
最后,我使用数字表获得了类似的结果。通过运行长度压缩,即使是一个巨大的数字表也会在红移集群上占用很少的空间。
test diststyle all
是一个无效的表名。使用create table test as…
或create table test\u diststyle\u all as…
和no(
在create table中as
之后)。as
@a_horse\u with_no\u name Redshift是postgres的一种经过大量修改的变体。在redshfit中创建表时,可以指定一种分发样式(distkey、diststyle-even或distyle-all)控制如何在集群中分布表。如果我用其他内容(例如select*from users limit 1
)替换as(…),则上述SQL完全有效查询运行得很好。我想我也会这么做。您制作的数字表有多大?您是否使用diststyle偶数分发了它?我有几个数字表,数量级递增(10/100/1000/10000/100000/1000000)。它们都设置为diststyle all
。