From a9aa4ff564bdf52e8b93b2e8fe0301fa2fb5bdba Mon Sep 17 00:00:00 2001 From: Joe Van Dyk Date: Fri, 8 Jun 2018 11:51:06 -0700 Subject: [PATCH] use a subselect instead of a CTE when building incremental models (must faster on postgresql due to the CTE optimization fence) --- .../macros/materializations/incremental/incremental.sql | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dbt/include/global_project/macros/materializations/incremental/incremental.sql b/dbt/include/global_project/macros/materializations/incremental/incremental.sql index 71945f29f08..6bab2ee753b 100644 --- a/dbt/include/global_project/macros/materializations/incremental/incremental.sql +++ b/dbt/include/global_project/macros/materializations/incremental/incremental.sql @@ -60,10 +60,7 @@ {%- call statement() -%} {% set tmp_table_sql -%} - with dbt_incr_sbq as ( - {{ sql }} - ) - select * from dbt_incr_sbq + select * from ({{ sql }}) as dbt_incr_sbq where ({{ sql_where }}) or ({{ sql_where }}) is null {%- endset %}