duckdb / duckdb-r

The duckdb R package
https://r.duckdb.org/
Other
104 stars 21 forks source link

connect to existing sqlite and postgres database #183

Open Yousuf28 opened 1 week ago

Yousuf28 commented 1 week ago

Hi, Thanks for the duckdb R package. I have sqlite and postgres database. I was able to install and load the extension like this

library(duckdb)
library(DBI)
con <- dbConnect(duckdb::duckdb())
dbExecute(con, "INSTALL 'sqlite_scanner.duckdb_extension.gz'")
dbExecute(con, "INSTALL 'postgres_scanner.duckdb_extension.gz'")
dbExecute(con, "LOAD postgres")
dbExecute(con, "LOAD sqlite")

untils this works fine. Now, How can I connect to my existing sqlite database. For example If I connect like this, I get error that database does not have ID table. But this database have ID table. What I am missing?

path <- 'file_path/sqlite/database.db'
con_sql <- DBI::dbConnect(duckdb(), path = path)
dbGetQuery(con_sql, 'select * from ID limit 5')

Also I would appreciate If anyone give an example how to connect to postgres database and query with an example.

eitsupi commented 1 week ago

If this is not an R-specific problem (i.e., if you reproduce the same problem using the duckdb CLI), I suggest you ask the question in the main DuckDB repository rather than here. https://github.com/duckdb/duckdb/discussions