349386 {
349387 bool or_replace_shorthand_set = false;
349388 string result;
349389
349390 result =
cte_map.ToString();
349391 result += "INSERT";
349392 if (on_conflict_info && on_conflict_info->action_type == OnConflictAction::REPLACE) {
349393 or_replace_shorthand_set = true;
349394 result += " OR REPLACE";
349395 }
349396 result += " INTO ";
349399 }
349402 }
349404
349405 if (table_ref && !table_ref->alias.empty()) {
349407 }
349408 if (
column_order == InsertColumnOrder::INSERT_BY_NAME) {
349409 result += " BY NAME";
349410 }
349412 result += " (";
349414 if (i > 0) {
349415 result += ", ";
349416 }
349418 }
349419 result += " )";
349420 }
349421 result += " ";
349423 if (values_list) {
349425 auto saved_alias = values_list->alias;
349426 values_list->alias = string();
349427 result += values_list->ToString();
349428 values_list->alias = saved_alias;
349432 } else {
349434 result += "DEFAULT VALUES";
349435 }
349436 if (!or_replace_shorthand_set && on_conflict_info) {
349437 auto &conflict_info = *on_conflict_info;
349438 result += " ON CONFLICT ";
349439
349440 if (!conflict_info.indexed_columns.empty()) {
349441 result += "(";
349442 auto &
columns = conflict_info.indexed_columns;
349445 if (++it !=
columns.end()) {
349446 result += ", ";
349447 }
349448 }
349449 result += " )";
349450 }
349451
349452
349453 if (conflict_info.condition) {
349454 result += " WHERE " + conflict_info.condition->ToString();
349455 }
349456 result += " " + OnConflictActionToString(conflict_info.action_type);
349457 if (conflict_info.set_info) {
349458 D_ASSERT(conflict_info.action_type == OnConflictAction::UPDATE);
349459 result += " SET ";
349460 auto &set_info = *conflict_info.set_info;
349461 D_ASSERT(set_info.columns.size() == set_info.expressions.size());
349462
349463 for (
idx_t i = 0; i < set_info.columns.size(); i++) {
349464 auto &column = set_info.columns[i];
349465 auto &expr = set_info.expressions[i];
349466 if (i) {
349467 result += ", ";
349468 }
349470 }
349471
349472 if (set_info.condition) {
349473 result += " WHERE " + set_info.condition->ToString();
349474 }
349475 }
349476 }
349478 result += " RETURNING ";
349480 if (i > 0) {
349481 result += ", ";
349482 }
349485 column +=
349487 }
349488 result += column;
349489 }
349490 }
349491 return result;
349492}
optional_ptr< ExpressionListRef > GetValuesList() const
Definition duckdb.cpp:349498
static string WriteOptionallyQuoted(const string &text, char quote='"', bool allow_caps = true, KeywordCategory category = KeywordCategory::KEYWORD_NONE)
Writes a string that is optionally quoted + escaped so it can be used as an identifier.
Definition duckdb.cpp:338034
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237