admin管理员组文章数量:1125480
Reading through the reference material- .html
Is there are reason the below code doesn't create the temp table?:
if (!require("pacman")
) install.packages("pacman")
pacman::p_load(
#add list of libraries here
DBI,
odbc,
RODBC,
stringr
)
DBI:dbSendStatement(con, "CREATE TABLE #SURGEONS(PROV_ID VARCHAR(18),PROV_NAME VARCHAR(123),SERV_NAME VARCHAR(9));")
When I run the below:
DBI::dbGetQuery(con, "SELECT * FROM #SURGEONS")
It errors out with: Invalid object name '#SURGEONS'
But when I feed it into dbCreateTable it works?
dbCreateTable(
conn = con,
name = "#SURGEONS",
fields = c(
PROV_ID = "VARCHAR(18)",
PROV_NAME = "VARCHAR(123)",
SERV_NAME = "VARCHAR(9)"
),
temporary = TRUE
)
And I run:
DBI::dbGetQuery(con, "SELECT * FROM #SURGEONS")
Then I don't get an error that the table wasn't created-
[1] PROV_ID PROV_NAME SERV_NAME
<0 rows> (or 0-length row.names)
Reading through the reference material- https://dbi.r-dbi.org/reference/dbSendStatement.html
Is there are reason the below code doesn't create the temp table?:
if (!require("pacman")
) install.packages("pacman")
pacman::p_load(
#add list of libraries here
DBI,
odbc,
RODBC,
stringr
)
DBI:dbSendStatement(con, "CREATE TABLE #SURGEONS(PROV_ID VARCHAR(18),PROV_NAME VARCHAR(123),SERV_NAME VARCHAR(9));")
When I run the below:
DBI::dbGetQuery(con, "SELECT * FROM #SURGEONS")
It errors out with: Invalid object name '#SURGEONS'
But when I feed it into dbCreateTable it works?
dbCreateTable(
conn = con,
name = "#SURGEONS",
fields = c(
PROV_ID = "VARCHAR(18)",
PROV_NAME = "VARCHAR(123)",
SERV_NAME = "VARCHAR(9)"
),
temporary = TRUE
)
And I run:
DBI::dbGetQuery(con, "SELECT * FROM #SURGEONS")
Then I don't get an error that the table wasn't created-
[1] PROV_ID PROV_NAME SERV_NAME
<0 rows> (or 0-length row.names)
Share
Improve this question
edited Jan 9 at 6:54
Gingie
asked Jan 9 at 6:48
GingieGingie
2012 silver badges7 bronze badges
2
|
1 Answer
Reset to default 0Roland answered in the comment-
Need to use dbExecute in this case and not dbSendStatement
本文标签: R DBI dbSendStatement not working for CREATE TABLEStack Overflow
版权声明:本文标题:R DBI dbSendStatement not working for CREATE TABLE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736667825a1946756.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
dbExecute
? – Roland Commented Jan 9 at 6:56