|
23 | 23 | #include "duckdb/common/arrow/physical_arrow_collector.hpp" |
24 | 24 | #include "duckdb_python/arrow/arrow_export_utils.hpp" |
25 | 25 |
|
| 26 | +#include <duckdb/main/relation/table_relation.hpp> |
| 27 | + |
26 | 28 | namespace duckdb { |
27 | 29 |
|
28 | 30 | DuckDBPyRelation::DuckDBPyRelation(shared_ptr<Relation> rel_p) : rel(std::move(rel_p)) { |
@@ -1511,7 +1513,7 @@ DuckDBPyRelation &DuckDBPyRelation::Execute() { |
1511 | 1513 | void DuckDBPyRelation::InsertInto(const string &table) { |
1512 | 1514 | AssertRelation(); |
1513 | 1515 | auto parsed_info = QualifiedName::Parse(table); |
1514 | | - auto insert = rel->InsertRel(parsed_info.schema, parsed_info.name); |
| 1516 | + auto insert = rel->InsertRel(parsed_info.catalog, parsed_info.schema, parsed_info.name); |
1515 | 1517 | PyExecuteRelation(insert); |
1516 | 1518 | } |
1517 | 1519 |
|
@@ -1565,14 +1567,24 @@ void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where) |
1565 | 1567 |
|
1566 | 1568 | void DuckDBPyRelation::Insert(const py::object ¶ms) { |
1567 | 1569 | AssertRelation(); |
1568 | | - if (!IsAcceptedInsertRelationType(*this->rel)) { |
| 1570 | + if (this->rel->type != RelationType::TABLE_RELATION) { |
1569 | 1571 | throw InvalidInputException("'DuckDBPyRelation.insert' can only be used on a table relation"); |
1570 | 1572 | } |
1571 | 1573 | vector<vector<Value>> values {DuckDBPyConnection::TransformPythonParamList(params)}; |
1572 | 1574 |
|
1573 | 1575 | D_ASSERT(py::gil_check()); |
1574 | 1576 | py::gil_scoped_release release; |
1575 | | - rel->Insert(values); |
| 1577 | + // Grab table info |
| 1578 | + auto table_relation = static_cast<TableRelation *>(this->rel.get()); |
| 1579 | + auto catalog = table_relation->description->database; |
| 1580 | + auto schema = table_relation->description->schema; |
| 1581 | + auto table = table_relation->description->table; |
| 1582 | + // Create a value relation |
| 1583 | + vector<string> column_names; |
| 1584 | + auto value_rel = |
| 1585 | + make_shared_ptr<ValueRelation>(this->rel->context->GetContext(), values, std::move(column_names), "values"); |
| 1586 | + // Now insert |
| 1587 | + value_rel->Insert(catalog, schema, table); |
1576 | 1588 | } |
1577 | 1589 |
|
1578 | 1590 | void DuckDBPyRelation::Create(const string &table) { |
|
0 commit comments