dplyr & monetdb - appropriate syntax for querying

2019-08-11 17:06发布

In monetdb I have set up a schema main and my tables are created into this schema.

For example, the department table is main.department.

With dplyr I try to query the table:

mdb <- src_monetdb(dbname="model", user="monetdb", password="monetdb")

tbl(mdb, "department")

But I get

Error in .local(conn, statement, ...) : 
  Unable to execute statement 'PREPARE SELECT * FROM "department"'.
Server says 'SELECT: no such table 'department'' [#42S02].

I tried to use "main.department" and other similar combinations with no luck.

What is the appropriate syntax?

标签: r dplyr monetdb
2条回答
Deceive 欺骗
2楼-- · 2019-08-11 17:51

There is a somewhat hacky workaround for this: We can manually set the default schema for the connection. I have a database testing, in there is a schema foo with a table called bar.

mdb <- src_monetdb("testing")
dbSendQuery(mdb$con, "SET SCHEMA foo");
t <- tbl(mdb, "bar")
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-11 17:55

The dbplyr package (a backend of dplyr for database connections) has a in_schema() function for these cases:

conn <- dbConnect(
  MonetDB.R(),
  host = "localhost",
  dbname = "model",
  user = "monetdb",
  password = "monetdb",
  timeout = 86400L
)

department = tbl(conn, dbplyr::in_schema("main", "department"))
查看更多
登录 后发表回答