From 442c8d49e6839165e5af80f7f6604079bb5ac67a Mon Sep 17 00:00:00 2001 From: Denis Hirn Date: Mon, 26 Feb 2024 08:31:30 +0100 Subject: [PATCH] Enable materialized CTEs in INSERT statements --- src/parser/transform/statement/transform_insert.cpp | 4 +--- test/sql/catalog/function/test_cte_macro.test | 3 --- test/sql/cte/materialized/dml_materialized_cte.test | 3 +-- test/sql/subquery/scalar/test_correlated_subquery.test | 3 --- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/parser/transform/statement/transform_insert.cpp b/src/parser/transform/statement/transform_insert.cpp index 30d7aeb62038..657de4a1a62d 100644 --- a/src/parser/transform/statement/transform_insert.cpp +++ b/src/parser/transform/statement/transform_insert.cpp @@ -28,9 +28,6 @@ unique_ptr Transformer::TransformInsert(duckdb_libpgquery::PGIn if (stmt.withClause) { TransformCTE(*PGPointerCast(stmt.withClause), result->cte_map, materialized_ctes); - if (!materialized_ctes.empty()) { - throw NotImplementedException("Materialized CTEs are not implemented for insert."); - } } // first check if there are any columns specified @@ -47,6 +44,7 @@ unique_ptr Transformer::TransformInsert(duckdb_libpgquery::PGIn } if (stmt.selectStmt) { result->select_statement = TransformSelect(stmt.selectStmt, false); + result->select_statement->node = TransformMaterializedCTE(std::move(result->select_statement->node), materialized_ctes); } else { result->default_values = true; } diff --git a/test/sql/catalog/function/test_cte_macro.test b/test/sql/catalog/function/test_cte_macro.test index 7de2d0757e0d..9572ba716a71 100644 --- a/test/sql/catalog/function/test_cte_macro.test +++ b/test/sql/catalog/function/test_cte_macro.test @@ -40,9 +40,6 @@ SELECT plus42(42) ---- 84 -# temporary solution until decorrelation of materialized CTEs is implemented -require noalternativeverify - query T SELECT plus42(a) FROM integers ---- diff --git a/test/sql/cte/materialized/dml_materialized_cte.test b/test/sql/cte/materialized/dml_materialized_cte.test index 7fadbb5f0fef..68790c3cb4e2 100644 --- a/test/sql/cte/materialized/dml_materialized_cte.test +++ b/test/sql/cte/materialized/dml_materialized_cte.test @@ -13,10 +13,9 @@ create table a(i integer); statement ok insert into a values (42); -statement error +statement ok WITH t(x) AS MATERIALIZED (VALUES (42)) INSERT INTO a (SELECT * FROM t); ----- statement error WITH t(x) AS MATERIALIZED (VALUES (42)) diff --git a/test/sql/subquery/scalar/test_correlated_subquery.test b/test/sql/subquery/scalar/test_correlated_subquery.test index dc8cb558590b..5100cafb38ad 100644 --- a/test/sql/subquery/scalar/test_correlated_subquery.test +++ b/test/sql/subquery/scalar/test_correlated_subquery.test @@ -14,9 +14,6 @@ CREATE TABLE integers(i INTEGER) statement ok INSERT INTO integers VALUES (1), (2), (3), (NULL) -# temporary solution until decorrelation of materialized CTEs is implemented -require noalternativeverify - # scalar select with correlation query II SELECT i, (SELECT 42+i1.i) AS j FROM integers i1 ORDER BY i;