1#include "duckdb/parser/statement/update_statement.hpp"
2#include "duckdb/parser/transformer.hpp"
3
4namespace duckdb {
5
6unique_ptr<UpdateSetInfo> Transformer::TransformUpdateSetInfo(duckdb_libpgquery::PGList *target_list,
7 duckdb_libpgquery::PGNode *where_clause) {
8 auto result = make_uniq<UpdateSetInfo>();
9
10 auto root = target_list;
11 for (auto cell = root->head; cell != nullptr; cell = cell->next) {
12 auto target = PGPointerCast<duckdb_libpgquery::PGResTarget>(ptr: cell->data.ptr_value);
13 result->columns.emplace_back(args&: target->name);
14 result->expressions.push_back(x: TransformExpression(node: target->val));
15 }
16 result->condition = TransformExpression(node: where_clause);
17 return result;
18}
19
20unique_ptr<UpdateStatement> Transformer::TransformUpdate(duckdb_libpgquery::PGUpdateStmt &stmt) {
21 auto result = make_uniq<UpdateStatement>();
22 if (stmt.withClause) {
23 TransformCTE(de_with_clause&: *PGPointerCast<duckdb_libpgquery::PGWithClause>(ptr: stmt.withClause), cte_map&: result->cte_map);
24 }
25
26 result->table = TransformRangeVar(root&: *stmt.relation);
27 if (stmt.fromClause) {
28 result->from_table = TransformFrom(root: stmt.fromClause);
29 }
30
31 result->set_info = TransformUpdateSetInfo(target_list: stmt.targetList, where_clause: stmt.whereClause);
32
33 // Grab and transform the returning columns from the parser.
34 if (stmt.returningList) {
35 TransformExpressionList(list&: *stmt.returningList, result&: result->returning_list);
36 }
37
38 return result;
39}
40
41} // namespace duckdb
42