Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbWriteTable() fails to write to existing table with non-default schema #191

Closed
EthanTaft opened this issue Jul 26, 2017 · 5 comments
Closed

Comments

@EthanTaft
Copy link

EthanTaft commented Jul 26, 2017

Reproducible Example:


#create a table in SSMS 
CREATE TABLE [guest].[MikeTestTable](
[a] [float] NULL,
[b] [float] NULL,
[c] [varchar](255) NULL)

#create a connection string to the database where the table was created
MSSQLConnectionString <- '
  driver={SQL Server};
  server=localhost;
  database=SAM;
  trustedConnection=true;
  '

#DBI Connection
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
                      .connection_string = MSSQLConnectionString)

#small dataframe we want to insert/append to the table we created at the beginning
df <- data.frame(a = c(10, 20, 30),
                 b = c(20, 40, 60),
                 c = c("oneT", "twoT", "threeT"))

#try to write contents of df to the table
DBI::dbWriteTable(conn = con,
                  name = SQL('guest.MikeTestTable'),
                  value = df,
                  append = TRUE)

Error: <SQL> 'CREATE TABLE guest.MikeTestTable (
  "a" FLOAT,
  "b" FLOAT,
  "c" varchar(255)
)
'
  nanodbc/nanodbc.cpp:1587: 42S01: [Microsoft][ODBC SQL Server Driver][SQL Server]
There is already an object named 'MikeTestTable' in the database. 

Question
Why is dbWriteTable trying to create a new table when append = TRUE ?

@EthanTaft
Copy link
Author

Sorry to write again. Have you guys looked into this issue yet? We are really in need of a solution right now but we know your time is busy. Cheers!

@EthanTaft
Copy link
Author

Issue solved here

@JackStat
Copy link

@EthanTaft The link is dead sir. Can you update?

@EthanTaft
Copy link
Author

@JackStat Thanks for pointing that out. This link should work.

@krlmlr
Copy link
Member

krlmlr commented Dec 4, 2017

Closing, see also #24.

@krlmlr krlmlr closed this as completed Dec 4, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants