1#include "duckdb/main/relation/insert_relation.hpp"
2#include "duckdb/parser/statement/insert_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
10InsertRelation::InsertRelation(shared_ptr<Relation> child_p, string schema_name, string table_name)
11 : Relation(child_p->context, RelationType::INSERT_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> InsertRelation::GetQueryNode() {
17 throw Exception("Cannot create a query node from a InsertRelation!");
18}
19
20BoundStatement InsertRelation::Bind(Binder &binder) {
21 InsertStatement stmt;
22 auto select = make_unique<SelectStatement>();
23 select->node = child->GetQueryNode();
24
25 stmt.schema = schema_name;
26 stmt.table = table_name;
27 stmt.select_statement = move(select);
28 return binder.Bind((SQLStatement &)stmt);
29}
30
31const vector<ColumnDefinition> &InsertRelation::Columns() {
32 return columns;
33}
34
35string InsertRelation::ToString(idx_t depth) {
36 string str = RenderWhitespace(depth) + "Insert\n";
37 return str + child->ToString(depth + 1);
38}
39
40} // namespace duckdb
41