diff --git a/src/duckdb_py/pyrelation.cpp b/src/duckdb_py/pyrelation.cpp index 58cfcc29..9b605128 100644 --- a/src/duckdb_py/pyrelation.cpp +++ b/src/duckdb_py/pyrelation.cpp @@ -153,7 +153,7 @@ unique_ptr DuckDBPyRelation::ProjectFromTypes(const py::object if (!projection.empty()) { projection += ", "; } - projection += names[i]; + projection += KeywordHelper::WriteOptionallyQuoted(names[i]); } } if (projection.empty()) { diff --git a/tests/fast/test_relation.py b/tests/fast/test_relation.py index f386b091..32349c68 100644 --- a/tests/fast/test_relation.py +++ b/tests/fast/test_relation.py @@ -688,3 +688,10 @@ def create_view(con, view_name: str) -> None: res = con.sql("select * from vw").fetchall() assert res == expected + + def test_relation_select_dtypes_quotes_identifiers_with_spaces(self, duckdb_cursor): + df = pd.DataFrame({"na me": ["alice", "bob"], "x": [1, 2]}) + rel = duckdb_cursor.from_df(df) + out = rel.select_dtypes([duckdb.sqltypes.VARCHAR]).fetchdf() + assert list(out.columns) == ["na me"] + assert out["na me"].tolist() == ["alice", "bob"]