1#include "duckdb/main/relation/create_view_relation.hpp"
2#include "duckdb/parser/statement/create_statement.hpp"
3#include "duckdb/parser/parsed_data/create_view_info.hpp"
4#include "duckdb/planner/binder.hpp"
5#include "duckdb/main/client_context.hpp"
6
7namespace duckdb {
8
9CreateViewRelation::CreateViewRelation(shared_ptr<Relation> child_p, string view_name, bool replace)
10 : Relation(child_p->context, RelationType::CREATE_VIEW_RELATION), child(move(child_p)), view_name(move(view_name)),
11 replace(replace) {
12 context.TryBindRelation(*this, this->columns);
13}
14
15unique_ptr<QueryNode> CreateViewRelation::GetQueryNode() {
16 throw InternalException("Cannot create a query node from a CreateViewRelation!");
17}
18
19BoundStatement CreateViewRelation::Bind(Binder &binder) {
20 CreateStatement stmt;
21 auto info = make_unique<CreateViewInfo>();
22 info->query = child->GetQueryNode();
23 info->view_name = view_name;
24 info->on_conflict = replace ? OnCreateConflict::REPLACE : OnCreateConflict::ERROR;
25 stmt.info = move(info);
26 return binder.Bind((SQLStatement &)stmt);
27}
28
29const vector<ColumnDefinition> &CreateViewRelation::Columns() {
30 return columns;
31}
32
33string CreateViewRelation::ToString(idx_t depth) {
34 string str = RenderWhitespace(depth) + "Create View\n";
35 return str + child->ToString(depth + 1);
36}
37
38} // namespace duckdb
39