Skip to content

Commit

Permalink
fix: create view nested query (#2637)
Browse files Browse the repository at this point in the history
closes #2636
  • Loading branch information
universalmind303 authored Feb 12, 2024
1 parent c9cc53c commit 674cf2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
19 changes: 8 additions & 11 deletions crates/sqlexec/src/planner/session_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,17 +1173,14 @@ impl<'a> SessionPlanner<'a> {
return Err(PlanError::UnsupportedFeature("view options"));
}

match query.body.as_ref() {
ast::SetExpr::Select(select) => select.projection.len(),
ast::SetExpr::Values(values) => {
values.rows.first().map(|first| first.len()).unwrap_or(0)
}
_ => {
return Err(PlanError::InvalidViewStatement {
msg: "view body must either be a SELECT or VALUES statement",
})
}
};
if !matches!(
query.body.as_ref(),
ast::SetExpr::Values(_) | ast::SetExpr::Query(_) | ast::SetExpr::Select(_)
) {
return Err(PlanError::InvalidViewStatement {
msg: "view body must either be a SELECT or VALUES statement",
});
}

let query_string = query.to_string();

Expand Down
17 changes: 17 additions & 0 deletions testdata/sqllogictests/create_view.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
statement ok
create schema create_view_schema;

statement ok
set search_path to create_view_schema;

statement ok
create view test as select 1 as a;

statement ok
CREATE VIEW view_yes_paren AS (SELECT 1);

query I
select * from view_yes_paren;
----
1

0 comments on commit 674cf2d

Please sign in to comment.