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