哪个函数执行授予或同义词?

Which function to execute grant or synonyms?

我有一个同义词声明:

CREATE OR REPLACE SYNONYM  sample-table-name FOR master.sample-table-name

我想通过使用 RJDBC 库的 R 语言来执行此操作。我尝试了不同的函数,包括 dbGetQuery 函数等。但是它无法执行此语句。

有人可以建议如何在 R 中执行这些语句。

我希望使用 dbExecute() 应该有效。如果做不到这一点,dbSendStatement() 几乎肯定可以工作,因为它似乎是为那种 DDL 而设计的。

dbGetQuery 上的文档说:

This method is for SELECT queries only

要查看您可以使用的功能,执行类似 ls('package:DBI') 的操作会很有帮助。根据文档:

dbExecute:

Executes a statement and returns the number of rows affected. dbExecute() comes with a default implementation (which should work with most backends) that calls dbSendStatement(), then dbGetRowsAffected(), ensuring that the result is always free-d by dbClearResult().

dbSendStatement:

The dbSendStatement() method only submits and synchronously executes the SQL data manipulation statement (e.g., UPDATE, DELETE, INSERT INTO, DROP TABLE, ...) to the database engine. To query the number of affected rows, call dbGetRowsAffected() on the returned result object. You must also call dbClearResult() after that. For interactive use, you should almost always prefer dbExecute().

编辑: 这些方法可能适用于 DBI 的其他实现,将来可能适用于 RJDBC。无论如何,看起来他们已经使用 dbSendQuery() 实现了 dbSendStatement(),因此他们不会为此目的工作。

RJDBC框架中,dbSendUpdate()就是你想要的

dbSendQuery and dbSendUpdate submit a SQL query to the database. The difference between the two is only that dbSendUpdate is used with DBML queries and thus doesn't return any result set.

已确认在另一个 DBMS 上使用类似查询:

dbSendStatement(conn,'SET search_path=public;')
#Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ",  : 
#Unable to retrieve JDBC result set for SET search_path=public; (No results were returned by the query.)

traceback()
#7: stop(..., " (", .jcall(x, "S", "getMessage"), ")")
#6: .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", 
#       statement)
#5: .local(conn, statement, ...)
#4: dbSendQuery(conn, statement, ...)
#3: dbSendQuery(conn, statement, ...)                ## this is the problem
#2: dbSendStatement(conn, "SET search_path=public;")
#1: dbSendStatement(conn, "SET search_path=public;")

dbSendUpdate(conn, 'SET search_path=public;')
# successful

dbCommit(conn)
# persist the change past the current session (RJDBC seems to give you transaction control here)