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(std::move(child_p)),
12 schema_name(std::move(schema_name)), table_name(std::move(table_name)) {
13 context.GetContext()->TryBindRelation(relation&: *this, result_columns&: this->columns);
14}
15
16BoundStatement InsertRelation::Bind(Binder &binder) {
17 InsertStatement stmt;
18 auto select = make_uniq<SelectStatement>();
19 select->node = child->GetQueryNode();
20
21 stmt.schema = schema_name;
22 stmt.table = table_name;
23 stmt.select_statement = std::move(select);
24 return binder.Bind(statement&: stmt.Cast<SQLStatement>());
25}
26
27const vector<ColumnDefinition> &InsertRelation::Columns() {
28 return columns;
29}
30
31string InsertRelation::ToString(idx_t depth) {
32 string str = RenderWhitespace(depth) + "Insert\n";
33 return str + child->ToString(depth: depth + 1);
34}
35
36} // namespace duckdb
37