1#include "duckdb/parser/statement/delete_statement.hpp"
2#include "duckdb/parser/query_node/select_node.hpp"
3
4namespace duckdb {
5
6DeleteStatement::DeleteStatement() : SQLStatement(StatementType::DELETE_STATEMENT) {
7}
8
9DeleteStatement::DeleteStatement(const DeleteStatement &other) : SQLStatement(other), table(other.table->Copy()) {
10 if (other.condition) {
11 condition = other.condition->Copy();
12 }
13 for (const auto &using_clause : other.using_clauses) {
14 using_clauses.push_back(x: using_clause->Copy());
15 }
16 for (auto &expr : other.returning_list) {
17 returning_list.emplace_back(args: expr->Copy());
18 }
19 cte_map = other.cte_map.Copy();
20}
21
22string DeleteStatement::ToString() const {
23 string result;
24 result = cte_map.ToString();
25 result += "DELETE FROM ";
26 result += table->ToString();
27 if (!using_clauses.empty()) {
28 result += " USING ";
29 for (idx_t i = 0; i < using_clauses.size(); i++) {
30 if (i > 0) {
31 result += ", ";
32 }
33 result += using_clauses[i]->ToString();
34 }
35 }
36 if (condition) {
37 result += " WHERE " + condition->ToString();
38 }
39
40 if (!returning_list.empty()) {
41 result += " RETURNING ";
42 for (idx_t i = 0; i < returning_list.size(); i++) {
43 if (i > 0) {
44 result += ", ";
45 }
46 result += returning_list[i]->ToString();
47 }
48 }
49 return result;
50}
51
52unique_ptr<SQLStatement> DeleteStatement::Copy() const {
53 return unique_ptr<DeleteStatement>(new DeleteStatement(*this));
54}
55
56} // namespace duckdb
57