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
7namespace duckdb {
8
9CreateTableRelation::CreateTableRelation(shared_ptr<Relation> child_p, string schema_name, string table_name)
10 : Relation(child_p->context, RelationType::CREATE_TABLE_RELATION), child(std::move(child_p)),
11 schema_name(std::move(schema_name)), table_name(std::move(table_name)) {
12 context.GetContext()->TryBindRelation(relation&: *this, result_columns&: this->columns);
13}
14
15BoundStatement CreateTableRelation::Bind(Binder &binder) {
16 auto select = make_uniq<SelectStatement>();
17 select->node = child->GetQueryNode();
18
19 CreateStatement stmt;
20 auto info = make_uniq<CreateTableInfo>();
21 info->schema = schema_name;
22 info->table = table_name;
23 info->query = std::move(select);
24 info->on_conflict = OnCreateConflict::ERROR_ON_CONFLICT;
25 stmt.info = std::move(info);
26 return binder.Bind(statement&: stmt.Cast<SQLStatement>());
27}
28
29const vector<ColumnDefinition> &CreateTableRelation::Columns() {
30 return columns;
31}
32
33string CreateTableRelation::ToString(idx_t depth) {
34 string str = RenderWhitespace(depth) + "Create Table\n";
35 return str + child->ToString(depth: depth + 1);
36}
37
38} // namespace duckdb
39