Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/duckdb_py/include/duckdb_python/pyrelation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ struct DuckDBPyRelation {

void InsertInto(const string &table);

void Insert(const py::object &params = py::list());
void Insert(const py::object &params = py::list()) const;
void Update(const py::object &set, const py::object &where = py::none());

void Create(const string &table);
Expand Down
10 changes: 3 additions & 7 deletions src/duckdb_py/pyrelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,14 +1511,10 @@ DuckDBPyRelation &DuckDBPyRelation::Execute() {
void DuckDBPyRelation::InsertInto(const string &table) {
AssertRelation();
auto parsed_info = QualifiedName::Parse(table);
auto insert = rel->InsertRel(parsed_info.schema, parsed_info.name);
auto insert = rel->InsertRel(parsed_info.catalog, parsed_info.schema, parsed_info.name);
PyExecuteRelation(insert);
}

static bool IsAcceptedInsertRelationType(const Relation &relation) {
return relation.type == RelationType::TABLE_RELATION;
}

void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where) {
AssertRelation();
unique_ptr<ParsedExpression> condition;
Expand Down Expand Up @@ -1563,9 +1559,9 @@ void DuckDBPyRelation::Update(const py::object &set_p, const py::object &where)
return rel->Update(std::move(names), std::move(expressions), std::move(condition));
}

void DuckDBPyRelation::Insert(const py::object &params) {
void DuckDBPyRelation::Insert(const py::object &params) const {
AssertRelation();
if (!IsAcceptedInsertRelationType(*this->rel)) {
if (this->rel->type != RelationType::TABLE_RELATION) {
throw InvalidInputException("'DuckDBPyRelation.insert' can only be used on a table relation");
}
vector<vector<Value>> values {DuckDBPyConnection::TransformPythonParamList(params)};
Expand Down
4 changes: 1 addition & 3 deletions tests/fast/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ def test_insert_with_schema(self, duckdb_cursor):
res = duckdb_cursor.table("not_main.tbl").fetchall()
assert len(res) == 10

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