Skip to content

Commit

Permalink
Enable materialized CTEs in INSERT statements
Browse files Browse the repository at this point in the history
  • Loading branch information
kryonix committed Feb 26, 2024
1 parent dec38d6 commit 442c8d4
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/parser/transform/statement/transform_insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ unique_ptr<InsertStatement> Transformer::TransformInsert(duckdb_libpgquery::PGIn
if (stmt.withClause) {
TransformCTE(*PGPointerCast<duckdb_libpgquery::PGWithClause>(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
Expand All @@ -47,6 +44,7 @@ unique_ptr<InsertStatement> 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;
}
Expand Down
3 changes: 0 additions & 3 deletions test/sql/catalog/function/test_cte_macro.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down
3 changes: 1 addition & 2 deletions test/sql/cte/materialized/dml_materialized_cte.test
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions test/sql/subquery/scalar/test_correlated_subquery.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 442c8d4

Please sign in to comment.