Skip to content

Commit c9fb976

Browse files
committed
Fix select_dtypes with quoted identifiers
1 parent 3f1f615 commit c9fb976

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/duckdb_py/pyrelation.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,20 @@
2424
#include "duckdb_python/arrow/arrow_export_utils.hpp"
2525

2626
namespace duckdb {
27-
27+
namespace {
28+
std::string QuoteIdentifier(const std::string &name) {
29+
std::string out;
30+
out.reserve(name.size() + 2);
31+
out.push_back('"');
32+
for (char c : name) {
33+
if (c == '"')
34+
out.push_back('"'); // escape " as ""
35+
out.push_back(c);
36+
}
37+
out.push_back('"');
38+
return out;
39+
}
40+
} // namespace
2841
DuckDBPyRelation::DuckDBPyRelation(shared_ptr<Relation> rel_p) : rel(std::move(rel_p)) {
2942
if (!rel) {
3043
throw InternalException("DuckDBPyRelation created without a relation");
@@ -153,7 +166,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::ProjectFromTypes(const py::object
153166
if (!projection.empty()) {
154167
projection += ", ";
155168
}
156-
projection += names[i];
169+
projection += QuoteIdentifier(names[i]);
157170
}
158171
}
159172
if (projection.empty()) {

0 commit comments

Comments
 (0)