Redshift重写视图创建逻辑

问题描述 投票:0回答:1

我使用以下查询在 Redshift 中创建了一个视图:

drop view if exists public.vw_some_table cascade;
create or replace view public.vw_some_table as
(
with interim_table as
    (select
         player_name
       , avg(score) as total_score
     from public.table_1
     group by 1
     )
   , final_table as
    (select
         player_name
       , total_score + 3 as total_score_adj
     from interim_table
     )
select *
from final_table);

但是,当我检查视图的 DDL 语句时,我发现它的存储方式如下,使用嵌套子查询,而不是 CTE:

create view vw_some_table(player_name, total_score_adj) as
SELECT final_table.player_name, final_table.total_score_adj
   FROM ( SELECT interim_table.player_name, interim_table.total_score + 3 AS total_score_adj
           FROM ( SELECT table_1.player_name, avg(table_1.score) AS total_score
                   FROM table_1
                  GROUP BY table_1.player_name) interim_table) final_table;

是否有办法阻止这种视图重构的发生?即使两者输出相同的结果,我也希望保留使用 CTE 定义的业务逻辑,以便将来更容易解释/维护。

sql postgresql amazon-redshift
1个回答
0
投票

是的,使用外部源代码控制:)在内部他们总是存储重写的普通视图的定义,超级烦人。至少他们保留了最初编写的垫子视图。

© www.soinside.com 2019 - 2024. All rights reserved.