Skip to content

Commit 13827e7

Browse files
Fix InsertRelation on attached database (#155)
fixes duckdb/duckdb#18396 related pr in core: duckdb/duckdb#19583 The checks of this PR can only run after duckdb/duckdb#19583 lands
2 parents 7ccc8e9 + 20bfd52 commit 13827e7

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
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: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,14 +1511,10 @@ DuckDBPyRelation &DuckDBPyRelation::Execute() {
15111511
void DuckDBPyRelation::InsertInto(const string &table) {
15121512
AssertRelation();
15131513
auto parsed_info = QualifiedName::Parse(table);
1514-
auto insert = rel->InsertRel(parsed_info.schema, parsed_info.name);
1514+
auto insert = rel->InsertRel(parsed_info.catalog, parsed_info.schema, parsed_info.name);
15151515
PyExecuteRelation(insert);
15161516
}
15171517

1518-
static bool IsAcceptedInsertRelationType(const Relation &relation) {
1519-
return relation.type == RelationType::TABLE_RELATION;
1520-
}
1521-
15221518
void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where) {
15231519
AssertRelation();
15241520
unique_ptr<ParsedExpression> condition;
@@ -1563,9 +1559,9 @@ void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where)
15631559
return rel->Update(std::move(names), std::move(expressions), std::move(condition));
15641560
}
15651561

1566-
void DuckDBPyRelation::Insert(const py::object &params) {
1562+
void DuckDBPyRelation::Insert(const py::object &params) const {
15671563
AssertRelation();
1568-
if (!IsAcceptedInsertRelationType(*this->rel)) {
1564+
if (this->rel->type != RelationType::TABLE_RELATION) {
15691565
throw InvalidInputException("'DuckDBPyRelation.insert' can only be used on a table relation");
15701566
}
15711567
vector<vector<Value>> values {DuckDBPyConnection::TransformPythonParamList(params)};

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)