Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not correctly escaping column names in sql for duckdb connection #6979

Closed
jestover opened this issue Dec 28, 2023 · 1 comment
Closed

Not correctly escaping column names in sql for duckdb connection #6979

jestover opened this issue Dec 28, 2023 · 1 comment

Comments

@jestover
Copy link

When querying a table with column names that start with a number the column is not returned if using a duckdb connection. Here is a small example showing how the query works with an SQLite connection and fails with duckdb.

library("RSQLite")
library("duckdb")
library("dplyr")

# Works!
sqlite_con <- dbConnect(SQLite())
copy_to(sqlite_con, tibble(first = 1:3, `2nd` = 4:6), "ex_tab")
tbl(sqlite_con, "ex_tab")
# Source:   table<ex_tab> [3 x 2]
# Database: sqlite 3.44.2 []
  first `2nd`
  <int> <int>
1     1     4
2     2     5
3     3     6
tbl(sqlite_con, "ex_tab") |> select(`2nd`)
# Source:   SQL [3 x 1]
# Database: sqlite 3.44.2 []
  `2nd`
  <int>
1     4
2     5
3     6

# Fails
duckdb_con <- dbConnect(duckdb())
copy_to(duckdb_con, tibble(first = 1:3, `2nd` = 4:6), "ex_tab")
tbl(duckdb_con, "ex_tab")
# Source:   table<ex_tab> [3 x 2]
# Database: DuckDB v0.9.2 [jes0129@Darwin 23.0.0:R 4.3.2/:memory:]
  first `2nd`
  <int> <int>
1     1     4
2     2     5
3     3     6
tbl(duckdb_con, "ex_tab") |> select(`2nd`)
# Source:   SQL [3 x 1]
# Database: DuckDB v0.9.2 [jes0129@Darwin 23.0.0:R 4.3.2/:memory:]
     nd
  <int>
1     2
2     2
3     2

# Comparing the results of show_query()
tbl(sqlite_con, "ex_tab") |> select(`2nd`) |> show_query()
<SQL>
SELECT `2nd`
FROM `ex_tab`
tbl(duckdb_con, "ex_tab") |> select(`2nd`) |> show_query()
<SQL>
SELECT 2nd
FROM ex_tab
@DavisVaughan
Copy link
Member

Moved to duckdb/duckdb-r#67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants