Skip to content

Commit 20bfd52

Browse files
committed
review feedback
1 parent 95a9968 commit 20bfd52

File tree

4 files changed

+5
-23
lines changed

4 files changed

+5
-23
lines changed

src/duckdb_py/include/duckdb_python/pyrelation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ struct DuckDBPyRelation {
235235

236236
void InsertInto(const string &table);
237237

238-
void Insert(const py::object &params = py::list());
238+
void Insert(const py::object &params = py::list()) const;
239239
void Update(const py::object &set, const py::object &where = py::none());
240240

241241
void Create(const string &table);

src/duckdb_py/pyrelation.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "duckdb/common/arrow/physical_arrow_collector.hpp"
2424
#include "duckdb_python/arrow/arrow_export_utils.hpp"
2525

26-
#include <duckdb/main/relation/table_relation.hpp>
27-
2826
namespace duckdb {
2927

3028
DuckDBPyRelation::DuckDBPyRelation(shared_ptr<Relation> rel_p) : rel(std::move(rel_p)) {
@@ -1517,10 +1515,6 @@ void DuckDBPyRelation::InsertInto(const string &table) {
15171515
PyExecuteRelation(insert);
15181516
}
15191517

1520-
static bool IsAcceptedInsertRelationType(const Relation &relation) {
1521-
return relation.type == RelationType::TABLE_RELATION;
1522-
}
1523-
15241518
void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where) {
15251519
AssertRelation();
15261520
unique_ptr<ParsedExpression> condition;
@@ -1565,7 +1559,7 @@ void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where)
15651559
return rel->Update(std::move(names), std::move(expressions), std::move(condition));
15661560
}
15671561

1568-
void DuckDBPyRelation::Insert(const py::object &params) {
1562+
void DuckDBPyRelation::Insert(const py::object &params) const {
15691563
AssertRelation();
15701564
if (this->rel->type != RelationType::TABLE_RELATION) {
15711565
throw InvalidInputException("'DuckDBPyRelation.insert' can only be used on a table relation");
@@ -1574,17 +1568,7 @@ void DuckDBPyRelation::Insert(const py::object &params) {
15741568

15751569
D_ASSERT(py::gil_check());
15761570
py::gil_scoped_release release;
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);
1571+
rel->Insert(values);
15881572
}
15891573

15901574
void DuckDBPyRelation::Create(const string &table) {

tests/fast/test_insert.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,4 @@ def test_insert_with_schema(self, duckdb_cursor):
2727
res = duckdb_cursor.table("not_main.tbl").fetchall()
2828
assert len(res) == 10
2929

30-
# TODO: This is not currently supported # noqa: TD002, TD003
31-
with pytest.raises(duckdb.CatalogException, match="Table with name tbl does not exist"):
32-
duckdb_cursor.table("not_main.tbl").insert([42, 21, 1337])
30+
duckdb_cursor.table("not_main.tbl").insert((42,))

0 commit comments

Comments
 (0)