1#include "duckdb/main/relation/delete_relation.hpp"
2#include "duckdb/parser/statement/delete_statement.hpp"
3#include "duckdb/planner/binder.hpp"
4#include "duckdb/main/client_context.hpp"
5#include "duckdb/parser/tableref/basetableref.hpp"
6
7namespace duckdb {
8
9DeleteRelation::DeleteRelation(ClientContext &context, unique_ptr<ParsedExpression> condition_p, string schema_name_p,
10 string table_name_p)
11 : Relation(context, RelationType::DELETE_RELATION), condition(move(condition_p)), schema_name(move(schema_name_p)),
12 table_name(move(table_name_p)) {
13 context.TryBindRelation(*this, this->columns);
14}
15
16unique_ptr<QueryNode> DeleteRelation::GetQueryNode() {
17 throw InternalException("Cannot create a query node from a DeleteRelation!");
18}
19
20BoundStatement DeleteRelation::Bind(Binder &binder) {
21 auto basetable = make_unique<BaseTableRef>();
22 basetable->schema_name = schema_name;
23 basetable->table_name = table_name;
24
25 DeleteStatement stmt;
26 stmt.condition = condition ? condition->Copy() : nullptr;
27 stmt.table = move(basetable);
28 return binder.Bind((SQLStatement &)stmt);
29}
30
31const vector<ColumnDefinition> &DeleteRelation::Columns() {
32 return columns;
33}
34
35string DeleteRelation::ToString(idx_t depth) {
36 string str = RenderWhitespace(depth) + "DELETE FROM " + table_name;
37 if (condition) {
38 str += " WHERE " + condition->ToString();
39 }
40 return str;
41}
42
43} // namespace duckdb
44