dplyr & monetdb - appropriate syntax for querying schema.table?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 11:56:31

问题


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?


回答1:


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")



回答2:


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"))


来源:https://stackoverflow.com/questions/32256666/dplyr-monetdb-appropriate-syntax-for-querying-schema-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!