1#include "duckdb/parser/statement/delete_statement.hpp"
2#include "duckdb/parser/transformer.hpp"
3
4namespace duckdb {
5
6unique_ptr<DeleteStatement> Transformer::TransformDelete(duckdb_libpgquery::PGDeleteStmt &stmt) {
7 auto result = make_uniq<DeleteStatement>();
8 if (stmt.withClause) {
9 TransformCTE(de_with_clause&: *PGPointerCast<duckdb_libpgquery::PGWithClause>(ptr: stmt.withClause), cte_map&: result->cte_map);
10 }
11
12 result->condition = TransformExpression(node: stmt.whereClause);
13 result->table = TransformRangeVar(root&: *stmt.relation);
14 if (result->table->type != TableReferenceType::BASE_TABLE) {
15 throw Exception("Can only delete from base tables!");
16 }
17 if (stmt.usingClause) {
18 for (auto n = stmt.usingClause->head; n != nullptr; n = n->next) {
19 auto target = PGPointerCast<duckdb_libpgquery::PGNode>(ptr: n->data.ptr_value);
20 auto using_entry = TransformTableRefNode(n&: *target);
21 result->using_clauses.push_back(x: std::move(using_entry));
22 }
23 }
24
25 if (stmt.returningList) {
26 TransformExpressionList(list&: *stmt.returningList, result&: result->returning_list);
27 }
28 return result;
29}
30
31} // namespace duckdb
32